|
4 | 4 | *--------------------------------------------------------------------------------------------*/
|
5 | 5 |
|
6 | 6 | import * as assert from 'assert';
|
| 7 | +import * as sinon from 'sinon'; |
7 | 8 | import { AiRelatedInformationService } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformationService';
|
8 | 9 | import { NullLogService } from 'vs/platform/log/common/log';
|
9 | 10 | import { CommandInformationResult, IAiRelatedInformationProvider, RelatedInformationType, SettingInformationResult } from 'vs/workbench/services/aiRelatedInformation/common/aiRelatedInformation';
|
@@ -66,4 +67,28 @@ suite('AiRelatedInformationService', () => {
|
66 | 67 | assert.strictEqual((result[0] as CommandInformationResult).command, command);
|
67 | 68 | assert.strictEqual((result[1] as SettingInformationResult).setting, setting);
|
68 | 69 | });
|
| 70 | + |
| 71 | + test('should return empty array on timeout', async () => { |
| 72 | + const clock = sinon.useFakeTimers({ |
| 73 | + shouldAdvanceTime: true, |
| 74 | + }); |
| 75 | + const provider: IAiRelatedInformationProvider = { |
| 76 | + provideAiRelatedInformation: () => new Promise((resolve) => { |
| 77 | + setTimeout(() => { |
| 78 | + resolve([{ type: RelatedInformationType.CommandInformation, command: 'command', weight: 1 }]); |
| 79 | + }, AiRelatedInformationService.DEFAULT_TIMEOUT + 100); |
| 80 | + }) |
| 81 | + }; |
| 82 | + |
| 83 | + service.registerAiRelatedInformationProvider(RelatedInformationType.CommandInformation, provider); |
| 84 | + |
| 85 | + try { |
| 86 | + const promise = service.getRelatedInformation('query', [RelatedInformationType.CommandInformation], CancellationToken.None); |
| 87 | + clock.tick(AiRelatedInformationService.DEFAULT_TIMEOUT + 200); |
| 88 | + const result = await promise; |
| 89 | + assert.strictEqual(result.length, 0); |
| 90 | + } finally { |
| 91 | + clock.restore(); |
| 92 | + } |
| 93 | + }); |
69 | 94 | });
|
0 commit comments