mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Count each epoll test deadline from its own arm call
The poller test recorded every initial deadline as the same start time plus the delay, while the poller reads the clock at each arm call; when arming the 2,000 timers took over 1 ms, the recorded order could differ from the delivered one by more than the assertion's slack. Each deadline now counts from the time read just before its scrp_timer_arm call, as the re-arm loop's do, and a 3 ms pause halfway through arming keeps the test exercising that case.
This commit is contained in:
@@ -38,10 +38,17 @@ int main(void) {
|
||||
assert(p != NULL);
|
||||
srand(7);
|
||||
double start = now_ms();
|
||||
/* Each deadline counts from its own arm call: arming takes time, here
|
||||
* stretched by a pause halfway, and the poller reads the clock at each
|
||||
* call. */
|
||||
for (int i = 0; i < KEYS; i++) {
|
||||
if (i == KEYS / 2)
|
||||
for (double until = now_ms() + 3; now_ms() < until;) {
|
||||
}
|
||||
double ms = 5 + rand() % 120;
|
||||
double t = now_ms();
|
||||
assert(scrp_timer_arm(p, &keys[i], ms, &keys[i]));
|
||||
deadline[i] = start + ms;
|
||||
deadline[i] = t + ms;
|
||||
state[i] = 1;
|
||||
}
|
||||
/* re-arm a third later and earlier, cancel a third (the heap and the key
|
||||
|
||||
Reference in New Issue
Block a user