Commit 7eb08b1
Moritz Scherer
[circt-lsp-server] Make time source injectable
Introduce an injectable clock and test-only wait shim to remove real sleeps
from `PendingChanges` logic in tests, while preserving production behavior.
- Add an **injectable time source**:
- `using SteadyClock = std::chrono::steady_clock;`
- `using NowFn = std::function<SteadyClock::time_point()>;`
- Store `NowFn nowFn` and a `bool useManualClock` in `PendingChangesMap`.
- Replace direct calls to `std::chrono::steady_clock::now()` with `nowFn()`.
- Add `waitForMinMs(uint64_t ms, SteadyClock::time_point start)`:
- **Prod path**: `std::this_thread::sleep_for(ms)`.
- **Test path** (`useManualClock`): busy-wait with `std::this_thread::yield()` until `nowFn()` reaches target.
- New ctor overload for tests:
- `PendingChangesMap(unsigned maxThreads, NowFn now)` -> enables manual clock mode.
- Dtor now calls `abort()` to ensure all pending work is cleared on teardown.
- Replace sleep in debounce worker:
- `sleep_for(ms)` -> `waitForMinMs(ms, scheduleTime)`.
- Add `ManualClock` with manual advancement (`advanceMs`) and `now()` accessor.
- Utility `advanceTestTime(clock, ms)` that advances test time and yields.
- `CallbackCapture::waitFor()` now uses a tight fixed 100ms window (no per-call timeout arg).
- Refactor tests to:
- Construct `PendingChangesMap` with manual clock (`PendingChangesMap(2, [&]{ return clock.now(); })`).
- Advance time deterministically instead of sleeping.
- Validate debounce min/obsolete/max-cap behaviors without flakiness.
- Adjust debounce cap in `MaxCapForcesFlushDuringContinuousTyping` to 1ms to tighten assertions.
- Sprinkle end-of-test large time advances to flush any queued workers.1 parent c429d8f commit 7eb08b1
File tree
3 files changed
+133
-44
lines changed- lib/Tools/circt-verilog-lsp-server/Utils
- unittests/Tools/circt-verilog-lsp-server/Utils
3 files changed
+133
-44
lines changedLines changed: 19 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
51 | | - | |
52 | | - | |
53 | | - | |
| 51 | + | |
54 | 52 | | |
55 | 53 | | |
56 | 54 | | |
| |||
71 | 69 | | |
72 | 70 | | |
73 | 71 | | |
74 | | - | |
| 72 | + | |
75 | 73 | | |
76 | 74 | | |
77 | 75 | | |
| |||
87 | 85 | | |
88 | 86 | | |
89 | 87 | | |
90 | | - | |
91 | | - | |
| 88 | + | |
92 | 89 | | |
93 | 90 | | |
94 | 91 | | |
| |||
98 | 95 | | |
99 | 96 | | |
100 | 97 | | |
101 | | - | |
| 98 | + | |
102 | 99 | | |
103 | 100 | | |
104 | 101 | | |
| |||
142 | 139 | | |
143 | 140 | | |
144 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
145 | 157 | | |
146 | 158 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
59 | | - | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
60 | 73 | | |
61 | 74 | | |
62 | 75 | | |
| |||
106 | 119 | | |
107 | 120 | | |
108 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
109 | 129 | | |
110 | 130 | | |
111 | 131 | | |
| |||
0 commit comments