mongodash 2.5.0 → 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.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitUntil = waitUntil;
|
|
4
|
+
const _debug = require("debug");
|
|
5
|
+
const debug = _debug('mongodash:testing');
|
|
4
6
|
/**
|
|
5
7
|
* Waits until the provided condition function returns true.
|
|
6
8
|
*
|
|
@@ -12,51 +14,55 @@ async function waitUntil(condition, options = {}) {
|
|
|
12
14
|
const { timeoutMs = 10000, pollIntervalMs = 50, stabilityDurationMs = 0 } = options;
|
|
13
15
|
const start = Date.now();
|
|
14
16
|
let deadline = start + timeoutMs;
|
|
15
|
-
let stableSince =
|
|
16
|
-
|
|
17
|
+
let stableSince = null;
|
|
18
|
+
debug(`Started. Timeout: ${timeoutMs}ms, Poll: ${pollIntervalMs}ms, Stability: ${stabilityDurationMs}ms`);
|
|
17
19
|
while (true) {
|
|
18
20
|
const now = Date.now();
|
|
19
|
-
// --- Time Jump Detection (Debug Support) ---
|
|
20
|
-
const elapsedSinceLastTick = now - lastTick;
|
|
21
|
-
// If elapsed time is significantly larger than poll interval (e.g. > 1s),
|
|
22
|
-
// we assume the process was paused (e.g. at a breakpoint).
|
|
23
|
-
if (elapsedSinceLastTick > 1000) {
|
|
24
|
-
const jump = elapsedSinceLastTick - pollIntervalMs; // Approximate jump
|
|
25
|
-
if (jump > 0) {
|
|
26
|
-
deadline += jump;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
lastTick = now;
|
|
30
|
-
// -------------------------------------------
|
|
31
21
|
if (now > deadline) {
|
|
22
|
+
debug(`Timeout! Elapsed: ${now - start}ms`);
|
|
32
23
|
throw new Error(`waitUntil timeout after ${timeoutMs}ms (adjusted for pauses)`);
|
|
33
24
|
}
|
|
34
25
|
let result;
|
|
35
26
|
try {
|
|
36
27
|
result = await condition();
|
|
37
28
|
}
|
|
38
|
-
catch (
|
|
39
|
-
|
|
40
|
-
result = false;
|
|
41
|
-
// Usually waitUntil swallows errors unless critical. Let's assume false.
|
|
42
|
-
// But if it's a logic error in condition, maybe we should throw.
|
|
43
|
-
// For now, let's treat throw as false for robustness in shaky tests.
|
|
29
|
+
catch (err) {
|
|
30
|
+
debug(`Condition threw error:`, err);
|
|
31
|
+
result = false;
|
|
44
32
|
}
|
|
45
33
|
if (result) {
|
|
46
34
|
if (stabilityDurationMs === 0) {
|
|
35
|
+
debug(`Condition met immediately.`);
|
|
47
36
|
return;
|
|
48
37
|
}
|
|
49
|
-
if (
|
|
38
|
+
if (stableSince === null) {
|
|
39
|
+
stableSince = now;
|
|
40
|
+
}
|
|
41
|
+
else if (now - stableSince >= stabilityDurationMs) {
|
|
42
|
+
debug(`Condition stable for ${now - stableSince}ms. Done.`);
|
|
50
43
|
return;
|
|
51
44
|
}
|
|
52
|
-
// Condition is true but haven't been stable long enough
|
|
53
|
-
// Continue loop
|
|
54
45
|
}
|
|
55
46
|
else {
|
|
56
|
-
|
|
57
|
-
|
|
47
|
+
if (stableSince !== null) {
|
|
48
|
+
debug(`Condition failed, resetting stability timer.`);
|
|
49
|
+
}
|
|
50
|
+
stableSince = null;
|
|
58
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();
|
|
59
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
|
+
// -------------------------------------------
|
|
60
66
|
}
|
|
61
67
|
}
|
|
62
68
|
//# sourceMappingURL=waitUntil.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntil.js","sourceRoot":"","sources":["../../../src/testing/waitUntil.ts"],"names":[],"mappings":";;
|
|
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,CAAC;QAAC,OAAO,G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
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.waitUntilReactiveTasksIdle = waitUntilReactiveTasksIdle;
|
|
4
|
+
const _debug = require("debug");
|
|
4
5
|
const reactiveTasks_1 = require("../reactiveTasks");
|
|
5
6
|
const waitUntil_1 = require("./waitUntil");
|
|
7
|
+
const debug = _debug('mongodash:testing');
|
|
6
8
|
/**
|
|
7
9
|
* Waits until the reactive task system is idle.
|
|
8
10
|
* "Idle" means:
|
|
@@ -19,11 +21,13 @@ async function waitUntilReactiveTasksIdle(customOptions = {}) {
|
|
|
19
21
|
// Accessing private planner via exposed getter for testing
|
|
20
22
|
const planner = reactiveTasks_1._scheduler.taskPlannerInstance;
|
|
21
23
|
if (planner && !planner.isEmpty) {
|
|
24
|
+
debug('Planner not empty');
|
|
22
25
|
return false;
|
|
23
26
|
}
|
|
24
27
|
// 2. Check Active Workers (Runner)
|
|
25
28
|
const runner = reactiveTasks_1._scheduler.concurrentRunnerInstance;
|
|
26
29
|
if (runner && runner.activeWorkers > 0) {
|
|
30
|
+
debug(`Active workers: ${runner.activeWorkers}`);
|
|
27
31
|
return false;
|
|
28
32
|
}
|
|
29
33
|
// 3. Check Database
|
|
@@ -56,6 +60,7 @@ async function waitUntilReactiveTasksIdle(customOptions = {}) {
|
|
|
56
60
|
],
|
|
57
61
|
});
|
|
58
62
|
if (count > 0) {
|
|
63
|
+
debug(`Collection ${entry.tasksCollection.collectionName} has ${count} active tasks`);
|
|
59
64
|
return false;
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"waitUntilReactiveTasksIdle.js","sourceRoot":"","sources":["../../../src/testing/waitUntilReactiveTasksIdle.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"waitUntilReactiveTasksIdle.js","sourceRoot":"","sources":["../../../src/testing/waitUntilReactiveTasksIdle.ts"],"names":[],"mappings":";;AAeA,gEAmEC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