mongodash 2.5.1 → 2.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -14,24 +14,10 @@ async function waitUntil(condition, options = {}) {
|
|
|
14
14
|
const { timeoutMs = 10000, pollIntervalMs = 50, stabilityDurationMs = 0 } = options;
|
|
15
15
|
const start = Date.now();
|
|
16
16
|
let deadline = start + timeoutMs;
|
|
17
|
-
let stableSince =
|
|
18
|
-
let lastTick = Date.now();
|
|
17
|
+
let stableSince = null;
|
|
19
18
|
debug(`Started. Timeout: ${timeoutMs}ms, Poll: ${pollIntervalMs}ms, Stability: ${stabilityDurationMs}ms`);
|
|
20
19
|
while (true) {
|
|
21
20
|
const now = Date.now();
|
|
22
|
-
// --- Time Jump Detection (Debug Support) ---
|
|
23
|
-
const elapsedSinceLastTick = now - lastTick;
|
|
24
|
-
// If elapsed time is significantly larger than poll interval (e.g. > 1s),
|
|
25
|
-
// we assume the process was paused (e.g. at a breakpoint).
|
|
26
|
-
if (elapsedSinceLastTick > 1000) {
|
|
27
|
-
const jump = elapsedSinceLastTick - pollIntervalMs; // Approximate jump
|
|
28
|
-
if (jump > 0) {
|
|
29
|
-
debug(`Time jump detected: ${jump}ms. Extending deadline.`);
|
|
30
|
-
deadline += jump;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
lastTick = now;
|
|
34
|
-
// -------------------------------------------
|
|
35
21
|
if (now > deadline) {
|
|
36
22
|
debug(`Timeout! Elapsed: ${now - start}ms`);
|
|
37
23
|
throw new Error(`waitUntil timeout after ${timeoutMs}ms (adjusted for pauses)`);
|
|
@@ -42,36 +28,41 @@ async function waitUntil(condition, options = {}) {
|
|
|
42
28
|
}
|
|
43
29
|
catch (err) {
|
|
44
30
|
debug(`Condition threw error:`, err);
|
|
45
|
-
|
|
46
|
-
result = false; // Condition failing throws implies not met? Or should we propagate?
|
|
47
|
-
// Usually waitUntil swallows errors unless critical. Let's assume false.
|
|
48
|
-
// But if it's a logic error in condition, maybe we should throw.
|
|
49
|
-
// For now, let's treat throw as false for robustness in shaky tests.
|
|
31
|
+
result = false;
|
|
50
32
|
}
|
|
51
33
|
if (result) {
|
|
52
34
|
if (stabilityDurationMs === 0) {
|
|
53
35
|
debug(`Condition met immediately.`);
|
|
54
36
|
return;
|
|
55
37
|
}
|
|
56
|
-
if (
|
|
38
|
+
if (stableSince === null) {
|
|
39
|
+
stableSince = now;
|
|
40
|
+
}
|
|
41
|
+
else if (now - stableSince >= stabilityDurationMs) {
|
|
57
42
|
debug(`Condition stable for ${now - stableSince}ms. Done.`);
|
|
58
43
|
return;
|
|
59
44
|
}
|
|
60
|
-
// Condition is true but haven't been stable long enough
|
|
61
|
-
// Continue loop
|
|
62
45
|
}
|
|
63
46
|
else {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// Avoid spamming log every tick if it was already failing
|
|
67
|
-
// Actually, stableSince is reset to 'now' every time it fails?
|
|
68
|
-
// No, only when it WAS true and becomes false?
|
|
69
|
-
// Original code: stableSince = now; on else.
|
|
70
|
-
// So if it keeps failing, stableSince keeps moving forward.
|
|
47
|
+
if (stableSince !== null) {
|
|
48
|
+
debug(`Condition failed, resetting stability timer.`);
|
|
71
49
|
}
|
|
72
|
-
stableSince =
|
|
50
|
+
stableSince = null;
|
|
73
51
|
}
|
|
52
|
+
// --- Time Jump Detection (Debug Support) ---
|
|
53
|
+
// Only measure time jump DURING the sleep, to avoid counting slow condition checks as "debugger pauses".
|
|
54
|
+
const sleepStart = Date.now();
|
|
74
55
|
await new Promise((r) => setTimeout(r, pollIntervalMs));
|
|
56
|
+
const sleepEnd = Date.now();
|
|
57
|
+
const actualSleep = sleepEnd - sleepStart;
|
|
58
|
+
// If actual sleep is significantly larger than requested (e.g. > 1s extra),
|
|
59
|
+
// we assume the process was paused (e.g. at a breakpoint) or system was suspended.
|
|
60
|
+
if (actualSleep > pollIntervalMs + 1000) {
|
|
61
|
+
const jump = actualSleep - pollIntervalMs;
|
|
62
|
+
debug(`Time jump detected: ${jump}ms. Extending deadline.`);
|
|
63
|
+
deadline += jump;
|
|
64
|
+
}
|
|
65
|
+
// -------------------------------------------
|
|
75
66
|
}
|
|
76
67
|
}
|
|
77
68
|
//# sourceMappingURL=waitUntil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntil.js","sourceRoot":"","sources":["../../../src/testing/waitUntil.ts"],"names":[],"mappings":";;AA4BA,
|
|
1
|
+
{"version":3,"file":"waitUntil.js","sourceRoot":"","sources":["../../../src/testing/waitUntil.ts"],"names":[],"mappings":";;AA4BA,8BA2DC;AAvFD,gCAAgC;AAChC,MAAM,KAAK,GAAG,MAAM,CAAC,mBAAmB,CAAC,CAAC;AAoB1C;;;;;;GAMG;AACI,KAAK,UAAU,SAAS,CAAC,SAA2C,EAAE,UAA4B,EAAE;IACvG,MAAM,EAAE,SAAS,GAAG,KAAK,EAAE,cAAc,GAAG,EAAE,EAAE,mBAAmB,GAAG,CAAC,EAAE,GAAG,OAAO,CAAC;IAEpF,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACzB,IAAI,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAC;IACjC,IAAI,WAAW,GAAkB,IAAI,CAAC;IAEtC,KAAK,CAAC,qBAAqB,SAAS,aAAa,cAAc,kBAAkB,mBAAmB,IAAI,CAAC,CAAC;IAE1G,OAAO,IAAI,EAAE,CAAC;QACV,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAEvB,IAAI,GAAG,GAAG,QAAQ,EAAE,CAAC;YACjB,KAAK,CAAC,qBAAqB,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC;YAC5C,MAAM,IAAI,KAAK,CAAC,2BAA2B,SAAS,0BAA0B,CAAC,CAAC;QACpF,CAAC;QAED,IAAI,MAAe,CAAC;QACpB,IAAI,CAAC;YACD,MAAM,GAAG,MAAM,SAAS,EAAE,CAAC;QAC/B,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