Change:
}); }); <del> async function withAsyncTestCodeEditorAndInlineCompletionsModel( </del> <ins> async function withAsyncTestCodeEditorAndInlineCompletionsModel<T>( </ins> text: string, options: TestCodeEditorCreationOptions & { provider?: InlineCompletionsProvider, fakeClock?: boolean }, <del> callback: (args: { editor: ITestCodeEditor, editorViewModel: ViewModel, model: InlineCompletionsModel, context: GhostTextContext }) => Promise<void> ): Promise<void> { const disposableStore = new DisposableStore(); if (options.provider) { const d = InlineCompletionsProviderRegistry.register({ pattern: '**' }, options.provider); disposableStore.add(d); } let clock: sinon.SinonFakeTimers | undefined; if (options.fakeClock) { clock = sinon.useFakeTimers(); } try { const p = withAsyncTestCodeEditor(text, options, async (editor, editorViewModel, instantiationService) => { const model = instantiationService.createInstance(InlineCompletionsModel, editor); const context = new GhostTextContext(model, editor); await callback({ editor, editorViewModel, model, context }); context.dispose(); model.dispose(); }); </del> <ins> callback: (args: { editor: ITestCodeEditor, editorViewModel: ViewModel, model: InlineCompletionsModel, context: GhostTextContext }) => Promise<T> ): Promise<T> { return await runWithFakedTimers({ useFakeTimers: options.fakeClock, }, async () => { const disposableStore = new DisposableStore(); try { if (options.provider) { const d = InlineCompletionsProviderRegistry.register({ pattern: '**' }, options.provider); disposableStore.add(d); } </ins> <del> const p2 = clock?.runAllAsync(); </del> <ins> let result: T; await withAsyncTestCodeEditor(text, options, async (editor, editorViewModel, instantiationService) => { const model = instantiationService.createInstance(InlineCompletionsModel, editor); const context = new GhostTextContext(model, editor); result = await callback({ editor, editorViewModel, model, context }); context.dispose(); model.dispose(); }); </ins> <del> await p; await p2; </del> <ins> if (options.provider instanceof MockInlineCompletionsProvider) { options.provider.assertNotCalledTwiceWithin50ms(); } </ins> <del> if (options.provider instanceof MockInlineCompletionsProvider) { options.provider.assertNotCalledTwiceWithin50ms(); </del> <ins> return result!; } finally { disposableStore.dispose(); </ins> } <del> } finally { clock?.restore(); disposableStore.dispose(); } </del> <ins> }); </ins> }

Discussion:
I used blame to find the owner of inline completions. Who should this be assigned to?
Looks like you did that wrong <img width="826" alt="Screen Shot 2021-07-12 at 12 53 21" src="https://user-"
From slack: I found the real issue of the flaky unit test. Apparently, some test that runs before the inline suggestion test (which fakes /) calls . spawns a (5 seconds) that calls itself (basically an endless loop over time). When the time is faked, my inline completion test waits for all scheduled timers to finish until the queue of scheduled timers is empty (assuming I am in control of all scheduled timers when my test is run). However, the loop in then causes an endless loop. My test gives up after running 1000 scheduled timers and I guess then things are in an inconsistent state. This only happens when my tests are run right before is about to run. If my tests a run in the 5s interval in which is not called, nothing bad happens. As a quick fix, I will change my tests to not wait for the timer queue to get empty. As a long term fix, I think tests should be isolated better - at least they should make really sure they clean up everything (such as disposables/timers/global handlers/etc.). Joh tracked this down to this leaking disposable: