Commit bac9000
Fix flaky integration test and clean up test patterns (#1575)
The "Change event includes old and new values" test had a race
condition: `setEnvironment(undefined, oldEnv)` fires an async event that
could be captured by the `TestEventHandler` registered immediately
after, causing the handler to see the wrong event.
### Changes
- **Fix race condition**: Add `waitForCondition` between the initial
`setEnvironment` and handler registration to ensure the first event has
fully propagated
- **Eliminate duplicate `getEnvironment` calls**: The original pattern
called `waitForCondition` (polling `getEnvironment` until ready) then
immediately re-fetched and asserted on a second `getEnvironment` call.
Combined these by capturing the result inside the `waitForCondition`
callback:
```typescript
// Before: fetch twice
await waitForCondition(async () => {
const e = await api.getEnvironment(undefined);
return !!e && e.environmentPath.fsPath === envToSet.environmentPath.fsPath;
}, 15_000, ...);
const retrieved = await api.getEnvironment(undefined); // redundant
assert.ok(retrieved, ...);
assert.strictEqual(retrieved.environmentPath.fsPath, ...);
// After: capture and reuse
let retrieved: PythonEnvironment | undefined;
await waitForCondition(async () => {
retrieved = await api.getEnvironment(undefined);
return !!retrieved && retrieved.environmentPath.fsPath === envToSet.environmentPath.fsPath;
}, 15_000, ...);
assert.ok(retrieved, ...);
assert.strictEqual(retrieved!.environmentPath.fsPath, ...);
```
- **Replace raw `setTimeout` with `waitForCondition`** in the
idempotency test — a fixed 500ms sleep is fragile on slow CI runners
- **Use top-level import** for `PythonEnvironment` instead of repeated
inline `import('../../api').PythonEnvironment` type expressions
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Eduardo Villalpando Mello <eduardovil@microsoft.com>1 parent 390625c commit bac9000
2 files changed
Lines changed: 73 additions & 57 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
363 | 363 | | |
364 | 364 | | |
365 | 365 | | |
366 | | - | |
367 | | - | |
368 | | - | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
369 | 380 | | |
370 | 381 | | |
371 | 382 | | |
| |||
443 | 454 | | |
444 | 455 | | |
445 | 456 | | |
446 | | - | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
447 | 469 | | |
448 | 470 | | |
449 | 471 | | |
| |||
488 | 510 | | |
489 | 511 | | |
490 | 512 | | |
491 | | - | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
492 | 525 | | |
493 | 526 | | |
494 | 527 | | |
| |||
Lines changed: 35 additions & 52 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 57 | + | |
62 | 58 | | |
63 | 59 | | |
64 | 60 | | |
| |||
96 | 92 | | |
97 | 93 | | |
98 | 94 | | |
99 | | - | |
| 95 | + | |
100 | 96 | | |
101 | 97 | | |
102 | | - | |
103 | 98 | | |
104 | 99 | | |
105 | 100 | | |
| |||
174 | 169 | | |
175 | 170 | | |
176 | 171 | | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
181 | 177 | | |
182 | 178 | | |
183 | | - | |
| 179 | + | |
184 | 180 | | |
185 | 181 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
192 | 189 | | |
193 | | - | |
| 190 | + | |
194 | 191 | | |
195 | 192 | | |
196 | 193 | | |
197 | 194 | | |
198 | | - | |
| 195 | + | |
199 | 196 | | |
200 | 197 | | |
201 | 198 | | |
| |||
257 | 254 | | |
258 | 255 | | |
259 | 256 | | |
260 | | - | |
| 257 | + | |
261 | 258 | | |
262 | | - | |
263 | | - | |
| 259 | + | |
| 260 | + | |
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
| |||
275 | 272 | | |
276 | 273 | | |
277 | 274 | | |
278 | | - | |
279 | | - | |
| 275 | + | |
| 276 | + | |
280 | 277 | | |
281 | | - | |
282 | | - | |
283 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
284 | 285 | | |
285 | | - | |
| 286 | + | |
286 | 287 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 288 | + | |
293 | 289 | | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | 290 | | |
308 | 291 | | |
309 | 292 | | |
| |||
0 commit comments