@flemist/test-variants 5.0.11 → 5.0.13

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,1033 +0,0 @@
1
- import { timeControllerDefault as K } from "@flemist/time-controller";
2
- import { formatAny as de, deepCloneJsonLike as Je } from "@flemist/simple-utils";
3
- import { isPromiseLike as M, waitMicrotasks as Xe, combineAbortSignals as oe } from "@flemist/async-utils";
4
- import { AbortError as Ze, AbortControllerFast as ie } from "@flemist/abort-controller-fast";
5
- import { poolWait as se, Pool as Ke } from "@flemist/time-limits";
6
- function Q() {
7
- if (typeof process < "u" && process.memoryUsage)
8
- try {
9
- return process.memoryUsage.rss();
10
- } catch {
11
- }
12
- if (typeof performance < "u") {
13
- const e = performance.memory;
14
- if (e)
15
- try {
16
- return e.usedJSHeapSize;
17
- } catch {
18
- }
19
- }
20
- return null;
21
- }
22
- const Qe = 1e3, q = [];
23
- function Ye(e) {
24
- return de(e, { pretty: !0, maxDepth: 5, maxItems: 50 });
25
- }
26
- function et(...e) {
27
- const n = e.map((t) => typeof t == "string" ? t : Ye(t)).join(" ");
28
- q.push(n), q.length > Qe && q.shift(), console.log(n);
29
- }
30
- function tt() {
31
- return q.join(`
32
- `);
33
- }
34
- globalThis.__getStressTestLogLast = tt;
35
- const me = (e, n) => {
36
- et(n);
37
- }, ge = (e) => de(e, {
38
- pretty: !0,
39
- maxDepth: 20,
40
- maxItems: 100,
41
- maxStringLength: 5e3,
42
- dontExpandClassInstances: !0,
43
- dontExpandFunctions: !0
44
- }), x = {
45
- start: !0,
46
- progress: 5e3,
47
- completed: !0,
48
- error: !0,
49
- modeChange: !0,
50
- debug: !1,
51
- func: me,
52
- format: ge
53
- }, rt = {
54
- start: !1,
55
- progress: !1,
56
- completed: !1,
57
- error: !1,
58
- modeChange: !1,
59
- debug: !1,
60
- func: me,
61
- format: ge
62
- };
63
- function pe(e) {
64
- return e === !1 ? rt : e === !0 || !e ? x : {
65
- start: e.start ?? x.start,
66
- progress: e.progress ?? x.progress,
67
- completed: e.completed ?? x.completed,
68
- error: e.error ?? x.error,
69
- modeChange: e.modeChange ?? x.modeChange,
70
- debug: e.debug ?? x.debug,
71
- func: e.func ?? x.func,
72
- format: e.format ?? x.format
73
- };
74
- }
75
- function nt(e, n) {
76
- const t = e.now();
77
- return {
78
- startTime: t,
79
- startMemory: n,
80
- debugMode: !1,
81
- tests: 0,
82
- iterations: 0,
83
- iterationsAsync: 0,
84
- prevLogTime: t,
85
- prevLogMemory: n,
86
- pendingModeChange: null,
87
- prevGcTime: t,
88
- prevGcIterations: 0,
89
- prevGcIterationsAsync: 0
90
- };
91
- }
92
- class I extends Ze {
93
- }
94
- const ot = 50, it = 5;
95
- function ae(e, n) {
96
- return typeof e == "number" ? { iterationsAsync: 0, iterationsSync: e } : e != null && typeof e == "object" ? e : n ? { iterationsAsync: 1, iterationsSync: 0 } : { iterationsAsync: 0, iterationsSync: 1 };
97
- }
98
- function st(e, n) {
99
- const t = n.log, i = n.pauseDebuggerOnError ?? !0;
100
- let o = null, a = 0;
101
- function r(l, u, c) {
102
- o == null && (o = { error: l, args: u, tests: c }, t.error && t.func(
103
- "error",
104
- `[test-variants] error variant: ${t.format(u)}
105
- tests: ${c}
106
- ${t.format(l)}`
107
- ));
108
- const d = Date.now();
109
- if (i)
110
- debugger;
111
- if (Date.now() - d > ot && a < it) {
112
- t.func(
113
- "debug",
114
- `[test-variants] debug iteration: ${a}`
115
- ), a++;
116
- return;
117
- }
118
- const y = o;
119
- throw o = null, n.onError && n.onError(y), y.error;
120
- }
121
- return function(u, c, d) {
122
- try {
123
- const h = e(u, d);
124
- return M(h) ? h.then(
125
- (y) => ae(y, !0),
126
- (y) => r(y, u, c)
127
- ) : ae(h, !1);
128
- } catch (h) {
129
- return h instanceof I ? void 0 : r(h, u, c);
130
- }
131
- };
132
- }
133
- function U(e, n, t) {
134
- for (let i = 0, o = e.length; i < o; i++)
135
- if (t ? t(e[i], n) : e[i] === n)
136
- return i;
137
- return -1;
138
- }
139
- function le(e, n, t, i) {
140
- const o = Object.keys(e.templates), a = {}, r = [], l = [], u = [], c = o.length;
141
- for (let d = 0; d < c; d++) {
142
- const h = o[d];
143
- a[h] = void 0, r.push(-1), l.push(void 0), u.push(null);
144
- }
145
- return {
146
- args: a,
147
- argsNames: o,
148
- indexes: r,
149
- argValues: l,
150
- argLimits: u,
151
- attempts: 0,
152
- templates: e,
153
- limitArgOnError: t,
154
- equals: n,
155
- includeErrorVariant: i ?? !1
156
- };
157
- }
158
- function O(e, n) {
159
- const t = e.templates.templates[n], i = e.templates.extra[n];
160
- let o;
161
- if (typeof t == "function" ? o = t(e.args) : o = t, i == null)
162
- return o;
163
- let a = null;
164
- const r = i.length;
165
- for (let l = 0; l < r; l++) {
166
- const u = i[l];
167
- U(o, u, e.equals) < 0 && (a == null ? a = [...o, u] : a.push(u));
168
- }
169
- return a ?? o;
170
- }
171
- function w(e, n, t) {
172
- const i = e.argValues[n].length;
173
- if (i === 0)
174
- return -1;
175
- const o = e.argLimits[n];
176
- if (o == null)
177
- return i - 1;
178
- let a = e.limitArgOnError;
179
- if (typeof a == "function") {
180
- const r = e.argsNames[n];
181
- a = a({
182
- name: r,
183
- values: e.argValues[n],
184
- maxValueIndex: o
185
- });
186
- }
187
- return !t || a ? Math.min(o, i - 1) : i - 1;
188
- }
189
- function T(e) {
190
- const n = e.indexes.length;
191
- for (let t = 0; t < n; t++) {
192
- const i = e.argLimits[t];
193
- if (i == null)
194
- return !1;
195
- const o = e.indexes[t];
196
- if (o > i)
197
- return !0;
198
- if (o < i)
199
- return !1;
200
- }
201
- return !e.includeErrorVariant;
202
- }
203
- function C(e) {
204
- const n = e.indexes.length;
205
- for (let t = 0; t < n; t++)
206
- e.indexes[t] = -1, e.argValues[t] = void 0, e.args[e.argsNames[t]] = void 0;
207
- }
208
- function he(e) {
209
- let n = !1, t = !0;
210
- const i = e.indexes.length;
211
- let o = i, a = !1, r = 0;
212
- for (; r < i; r++) {
213
- const l = e.argValues[r] == null;
214
- (l || a) && (l && (n = !0), e.argValues[r] = O(
215
- e,
216
- e.argsNames[r]
217
- ));
218
- const u = w(
219
- e,
220
- r,
221
- r > o
222
- );
223
- if (u < 0) {
224
- t = !1, e.indexes[r] = -1;
225
- break;
226
- }
227
- l && (e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0]), (a || e.indexes[r] > u) && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u], a = !0), o === i && e.indexes[r] < u && (o = r);
228
- }
229
- if (T(e))
230
- return C(e), !1;
231
- if (n && t)
232
- return !0;
233
- for (r--; r >= 0; r--) {
234
- if (e.argValues[r] == null)
235
- continue;
236
- let l = r > o;
237
- const u = w(e, r, l), c = e.indexes[r] + 1;
238
- if (c <= u) {
239
- e.indexes[r] = c, e.args[e.argsNames[r]] = e.argValues[r][c], c < u && (l = !0);
240
- for (let d = r + 1; d < i; d++)
241
- e.args[e.argsNames[d]] = void 0;
242
- for (r++; r < i; r++) {
243
- e.argValues[r] = O(
244
- e,
245
- e.argsNames[r]
246
- );
247
- const d = w(e, r, l);
248
- if (d < 0)
249
- break;
250
- e.indexes[r] = 0, e.args[e.argsNames[r]] = e.argValues[r][0], d > 0 && (l = !0);
251
- }
252
- if (r >= i)
253
- return T(e) ? (C(e), !1) : !0;
254
- }
255
- }
256
- return C(e), !1;
257
- }
258
- function z(e) {
259
- T(e) && C(e);
260
- let n = !1, t = !0;
261
- const i = e.indexes.length;
262
- let o = i, a = !1, r = 0;
263
- for (; r < i; r++) {
264
- const l = e.argValues[r] == null;
265
- (l || a) && (l && (n = !0), e.argValues[r] = O(
266
- e,
267
- e.argsNames[r]
268
- ));
269
- const u = w(
270
- e,
271
- r,
272
- r > o
273
- );
274
- if (u < 0) {
275
- t = !1, e.indexes[r] = -1;
276
- break;
277
- }
278
- l && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u]), (a || e.indexes[r] > u) && (e.indexes[r] = u, e.args[e.argsNames[r]] = e.argValues[r][u], a = !0), o === i && e.indexes[r] < u && (o = r);
279
- }
280
- if ((n || a) && t && !T(e))
281
- return !0;
282
- for (r--; r >= 0; r--) {
283
- if (e.argValues[r] == null)
284
- continue;
285
- let l = r > o;
286
- const u = w(e, r, l);
287
- let c = e.indexes[r] - 1;
288
- if (c > u && (c = u), c >= 0) {
289
- e.indexes[r] = c, e.args[e.argsNames[r]] = e.argValues[r][c], c < u && (l = !0);
290
- for (let d = r + 1; d < i; d++)
291
- e.args[e.argsNames[d]] = void 0;
292
- for (r++; r < i; r++) {
293
- e.argValues[r] = O(
294
- e,
295
- e.argsNames[r]
296
- );
297
- const d = w(e, r, l);
298
- if (d < 0)
299
- break;
300
- e.indexes[r] = d, e.args[e.argsNames[r]] = e.argValues[r][d], d > 0 && (l = !0);
301
- }
302
- if (r >= i)
303
- return !0;
304
- }
305
- }
306
- return C(e), !1;
307
- }
308
- function at(e, n) {
309
- C(e);
310
- const t = e.argsNames, i = t.length;
311
- let o = !1;
312
- for (let a = 0; a < i; a++) {
313
- const r = t[a], l = n[r];
314
- if (l === void 0)
315
- return null;
316
- e.argValues[a] = O(e, r);
317
- const u = w(e, a, o);
318
- if (u < 0)
319
- return null;
320
- const c = U(
321
- e.argValues[a],
322
- l,
323
- e.equals
324
- );
325
- if (c < 0 || c > u)
326
- return null;
327
- e.indexes[a] = c, e.args[e.argsNames[a]] = e.argValues[a][c], e.indexes[a] < u && (o = !0);
328
- }
329
- return T(e) ? null : e.indexes.slice();
330
- }
331
- function lt(e) {
332
- const n = e.indexes.length;
333
- if (n === 0)
334
- return !1;
335
- let t = !1;
336
- for (let i = 0; i < n; i++) {
337
- e.argValues[i] = O(e, e.argsNames[i]);
338
- const o = w(e, i, t);
339
- if (o < 0)
340
- return Math.random() < 0.5 ? he(e) : z(e);
341
- e.indexes[i] = Math.floor(Math.random() * (o + 1)), e.args[e.argsNames[i]] = e.argValues[i][e.indexes[i]], e.indexes[i] < o && (t = !0);
342
- }
343
- return T(e) ? z(e) : !0;
344
- }
345
- function _(e) {
346
- return e.mode === "forward" || e.mode === "backward";
347
- }
348
- function ut(e, n, t, i) {
349
- const o = n[t], a = e.templates[t];
350
- if (typeof a != "function") {
351
- if (U(a, o, i) >= 0)
352
- return;
353
- a.push(o);
354
- return;
355
- }
356
- const r = e.extra[t];
357
- if (r == null) {
358
- e.extra[t] = [o];
359
- return;
360
- }
361
- U(r, o, i) >= 0 || r.push(o);
362
- }
363
- function ft(e, n, t) {
364
- for (const i in n)
365
- if (Object.prototype.hasOwnProperty.call(n, i)) {
366
- if (i === "seed")
367
- continue;
368
- ut(e, n, i, t);
369
- }
370
- }
371
- function ue(e, n) {
372
- for (const t in n)
373
- if (Object.prototype.hasOwnProperty.call(n, t)) {
374
- if (t === "seed")
375
- continue;
376
- if (!e[t])
377
- return !1;
378
- }
379
- return !0;
380
- }
381
- const ct = [{ mode: "forward" }];
382
- function dt(e) {
383
- const {
384
- argsTemplates: n,
385
- equals: t,
386
- limitArgOnError: i,
387
- includeErrorVariant: o,
388
- getSeed: a,
389
- iterationModes: r,
390
- onModeChange: l,
391
- limitCompletionCount: u,
392
- limitTests: c,
393
- limitTime: d
394
- } = e, h = e.timeController ?? K, y = {
395
- templates: Je(n),
396
- extra: {}
397
- }, p = r == null || r.length === 0 ? ct : r, b = [];
398
- let E = null, L = null, g = 0, S = 0, V = !1, P = 0;
399
- function $() {
400
- V || (V = !0, P = h.now(), xe(), g = 0, te(), we());
401
- }
402
- function xe() {
403
- for (let s = 0, f = p.length; s < f; s++)
404
- b.push(Se());
405
- }
406
- function Se() {
407
- return {
408
- navigationState: le(
409
- y,
410
- t ?? null,
411
- i ?? null,
412
- o ?? null
413
- ),
414
- cycleCount: 0,
415
- completedCount: 0,
416
- testsInLastTurn: 0,
417
- tryNextVariantAttempts: 0,
418
- startTime: null
419
- };
420
- }
421
- function we() {
422
- E = le(
423
- y,
424
- t ?? null,
425
- // Initial values; overwritten in calcIndexes before each use
426
- !1,
427
- !1
428
- );
429
- }
430
- function te() {
431
- l?.({
432
- mode: p[g],
433
- modeIndex: g,
434
- tests: S
435
- });
436
- }
437
- function Me(s) {
438
- $(), ue(y.templates, s) && ft(y, s, t);
439
- }
440
- function re(s, f) {
441
- return $(), ue(y.templates, s) ? (E.limitArgOnError = f?.limitArg ?? i ?? null, E.includeErrorVariant = f?.includeLimit ?? o ?? !1, at(E, s)) : null;
442
- }
443
- function Ie(s) {
444
- const f = s?.args;
445
- if (f == null)
446
- return;
447
- $();
448
- const m = re(f);
449
- if (m != null) {
450
- L = {
451
- args: f,
452
- error: s?.error,
453
- tests: s?.tests ?? S
454
- }, E.argLimits = m;
455
- for (let v = 0, D = b.length; v < D; v++) {
456
- const j = b[v].navigationState;
457
- j.argLimits = m;
458
- }
459
- }
460
- }
461
- function Te() {
462
- return $(), Ve();
463
- }
464
- function Ve() {
465
- for (; ; ) {
466
- if (!Ae())
467
- return null;
468
- for (; ; ) {
469
- const s = qe();
470
- if (s != null)
471
- return b[g].testsInLastTurn++, S++, s;
472
- if ($e()) {
473
- if (!Ge())
474
- return null;
475
- _e();
476
- break;
477
- }
478
- }
479
- }
480
- }
481
- function Ae() {
482
- return !(Ce() || Oe() || G() && (Le() || !Ne()) || !Pe());
483
- }
484
- function Ce() {
485
- return c != null && S >= c;
486
- }
487
- function Oe() {
488
- return d != null && h.now() - P >= d;
489
- }
490
- function Le() {
491
- if (!G())
492
- throw new Error("Unexpected behavior");
493
- return u != null && u <= 0;
494
- }
495
- function Ne() {
496
- if (!G())
497
- throw new Error("Unexpected behavior");
498
- for (let s = 0, f = p.length; s < f; s++)
499
- if (A(p[s]) && R(s))
500
- return !0;
501
- return !1;
502
- }
503
- function Pe() {
504
- for (let s = 0, f = p.length; s < f; s++)
505
- if (R(s))
506
- return !0;
507
- return !1;
508
- }
509
- function $e() {
510
- g++;
511
- const s = g >= p.length;
512
- return s && (g = 0), te(), s;
513
- }
514
- function Ge() {
515
- if (G()) {
516
- const s = De();
517
- if (u != null && s >= u)
518
- return !1;
519
- }
520
- return !0;
521
- }
522
- function G() {
523
- for (let s = 0, f = p.length; s < f; s++)
524
- if (_(p[s]))
525
- return !0;
526
- return !1;
527
- }
528
- function De() {
529
- let s = !1, f = 1 / 0;
530
- for (let m = 0, v = b.length; m < v; m++) {
531
- const D = b[m], j = p[m];
532
- _(j) && (s = !0, R(m) && D.completedCount < f && (f = D.completedCount));
533
- }
534
- if (!s)
535
- throw new Error("Unexpected behavior");
536
- return f;
537
- }
538
- function R(s) {
539
- const f = p[s], m = b[s];
540
- return f.limitTests != null && f.limitTests <= 0 || A(f) && (f.cycles != null && f.cycles <= 0 || f.attemptsPerVariant != null && f.attemptsPerVariant <= 0) ? !1 : m.tryNextVariantAttempts < 2;
541
- }
542
- function _e() {
543
- g = 0;
544
- for (let s = 0, f = b.length; s < f; s++) {
545
- const m = b[s];
546
- m.testsInLastTurn = 0, m.startTime = null;
547
- }
548
- }
549
- function qe() {
550
- let s = 0;
551
- for (; s < 2; ) {
552
- if (!Ue())
553
- return null;
554
- const f = je();
555
- if (f != null)
556
- return f;
557
- if (A(p[g]) && Fe())
558
- return null;
559
- s++;
560
- }
561
- return null;
562
- }
563
- function Ue() {
564
- const s = p[g];
565
- return !(Be() || ke() || A(s) && !Re(g));
566
- }
567
- function Be() {
568
- const s = p[g], f = b[g];
569
- return s.limitTests != null && f.testsInLastTurn >= s.limitTests;
570
- }
571
- function ke() {
572
- const s = p[g], f = b[g];
573
- return s.limitTime != null && f.startTime != null && h.now() - f.startTime >= s.limitTime;
574
- }
575
- function A(s) {
576
- return _(s);
577
- }
578
- function Re(s) {
579
- const f = p[s], m = b[s];
580
- if (!A(f))
581
- throw new Error("Unexpected behavior");
582
- return m.cycleCount < (f.cycles ?? 1);
583
- }
584
- function Fe() {
585
- const s = p[g], f = b[g];
586
- if (!A(s))
587
- throw new Error("Unexpected behavior");
588
- return f.cycleCount++, f.cycleCount >= (s.cycles ?? 1) ? (f.cycleCount = 0, f.completedCount++, !0) : !1;
589
- }
590
- function je() {
591
- const s = p[g], f = b[g], m = f.navigationState;
592
- if (N(s)) {
593
- if (F())
594
- return null;
595
- const v = We();
596
- if (v != null)
597
- return f.startTime == null && (f.startTime = h.now()), v;
598
- }
599
- return He() ? (f.tryNextVariantAttempts = 0, N(s) && ze(), f.startTime == null && (f.startTime = h.now()), ne(m.args)) : (f.tryNextVariantAttempts++, null);
600
- }
601
- function We() {
602
- const s = p[g], m = b[g].navigationState;
603
- if (!N(s))
604
- throw new Error("Unexpected behavior");
605
- if (F())
606
- throw new Error("Unexpected behavior");
607
- const v = s.attemptsPerVariant ?? 1;
608
- return m.attempts > 0 && m.attempts < v ? T(m) ? null : (m.attempts++, ne(m.args)) : null;
609
- }
610
- function ze() {
611
- const s = p[g], m = b[g].navigationState;
612
- if (!N(s))
613
- throw new Error("Unexpected behavior");
614
- if (F())
615
- throw new Error("Unexpected behavior");
616
- m.attempts = 1;
617
- }
618
- function N(s) {
619
- return _(s);
620
- }
621
- function F() {
622
- const s = p[g];
623
- if (!N(s))
624
- throw new Error("Unexpected behavior");
625
- return (s.attemptsPerVariant ?? 1) <= 0;
626
- }
627
- function He() {
628
- const s = p[g], m = b[g].navigationState;
629
- switch (s.mode) {
630
- case "forward":
631
- return he(m);
632
- case "backward":
633
- return z(m);
634
- case "random":
635
- return lt(m);
636
- default:
637
- throw new Error(`Unknown mode: ${s.mode}`);
638
- }
639
- }
640
- function ne(s) {
641
- const f = { ...s };
642
- return a != null && (f.seed = a({ tests: S })), f;
643
- }
644
- return {
645
- get limit() {
646
- return L;
647
- },
648
- get modeIndex() {
649
- return g;
650
- },
651
- get modeConfigs() {
652
- return p;
653
- },
654
- get modeStates() {
655
- return b;
656
- },
657
- get tests() {
658
- return S;
659
- },
660
- calcIndexes: re,
661
- extendTemplates: Me,
662
- addLimit: Ie,
663
- next: Te
664
- };
665
- }
666
- function Y(e) {
667
- if (e == null || e <= 0)
668
- throw new Error(`Iterations = ${e}`);
669
- e--;
670
- const n = Xe().then(() => e);
671
- return e <= 0 ? n : n.then(Y);
672
- }
673
- function mt(e, n, t) {
674
- const i = n.limit ? {
675
- error: n.limit.error,
676
- args: n.limit.args,
677
- tests: n.limit.tests
678
- } : null;
679
- if (i && !t)
680
- throw i.error;
681
- return {
682
- iterations: e.iterations,
683
- bestError: i
684
- };
685
- }
686
- const fe = 2 ** 31;
687
- function gt(e) {
688
- if (e == null)
689
- return { parallel: 1, sequentialOnError: !1 };
690
- if (typeof e == "boolean")
691
- return {
692
- parallel: e ? fe : 1,
693
- sequentialOnError: !1
694
- };
695
- if (typeof e == "number")
696
- return { parallel: e > 0 ? e : 1, sequentialOnError: !1 };
697
- const n = e.count;
698
- let t = 1;
699
- return n === !0 ? t = fe : typeof n == "number" && n > 0 && (t = n), {
700
- parallel: t,
701
- sequentialOnError: e.sequentialOnError ?? !1
702
- };
703
- }
704
- function pt(e) {
705
- const n = e?.saveErrorVariants, t = n && e.createSaveErrorVariantsStore ? e.createSaveErrorVariantsStore(n) : null, i = e?.findBestError, { parallel: o, sequentialOnError: a } = gt(
706
- e?.parallel
707
- );
708
- return {
709
- store: t,
710
- GC_Iterations: e?.GC_Iterations ?? 1e6,
711
- GC_IterationsAsync: e?.GC_IterationsAsync ?? 1e4,
712
- GC_Interval: e?.GC_Interval ?? 1e3,
713
- logOptions: pe(e?.log),
714
- abortSignalExternal: e?.abortSignal,
715
- findBestError: i,
716
- dontThrowIfError: i?.dontThrowIfError,
717
- timeController: e?.timeController ?? K,
718
- parallel: o,
719
- sequentialOnError: a
720
- };
721
- }
722
- function B(e, n, t) {
723
- const { options: i, variantsIterator: o } = e, a = o.limit?.args ?? n;
724
- if (!i.store)
725
- return;
726
- const r = i.store.save(a);
727
- if (t)
728
- return r;
729
- }
730
- function ht(e, n, t, i) {
731
- const { abortControllerParallel: o, state: a, options: r } = e, { logOptions: l } = r;
732
- if (e.options.findBestError)
733
- e.variantsIterator.addLimit({ args: n, error: t, tests: i }), a.debugMode = !1, B(e, n, !1), r.sequentialOnError && !o.signal.aborted ? (l.debug && l.func(
734
- "debug",
735
- "[test-variants] sequentialOnError: aborting parallel, switching to sequential"
736
- ), o.abort(new I())) : l.debug && l.func(
737
- "debug",
738
- "[test-variants] parallel error in findBestError mode, continuing with new limits"
739
- );
740
- else {
741
- if (o.signal.aborted)
742
- return;
743
- B(e, n, !1), o.abort(t);
744
- }
745
- }
746
- function ce(e, n, t, i) {
747
- const { state: o } = e;
748
- if (e.options.findBestError) {
749
- e.variantsIterator.addLimit({ args: n, error: t, tests: i });
750
- const r = B(e, n, !0);
751
- if (r)
752
- return r.then(() => {
753
- o.debugMode = !1;
754
- });
755
- o.debugMode = !1;
756
- return;
757
- }
758
- const a = B(e, n, !0);
759
- if (a)
760
- return a.then(() => {
761
- throw t;
762
- });
763
- throw t;
764
- }
765
- function bt(e, n) {
766
- const { GC_Iterations: t, GC_IterationsAsync: i, GC_Interval: o } = e.options;
767
- return t > 0 && e.state.iterations - e.state.prevGcIterations >= t || i > 0 && e.state.iterationsAsync - e.state.prevGcIterationsAsync >= i || o > 0 && n - e.state.prevGcTime >= o;
768
- }
769
- async function yt(e, n) {
770
- e.prevGcIterations = e.iterations, e.prevGcIterationsAsync = e.iterationsAsync, e.prevGcTime = n, await Y(1);
771
- }
772
- function ee(e) {
773
- const n = e / 1e3;
774
- if (n < 60)
775
- return `${n.toFixed(1)}s`;
776
- const t = n / 60;
777
- return t < 60 ? `${t.toFixed(1)}m` : `${(t / 60).toFixed(1)}h`;
778
- }
779
- function H(e) {
780
- const n = e / 1073741824;
781
- if (n >= 1)
782
- return n >= 10 ? `${Math.round(n)}GB` : `${n.toFixed(1)}GB`;
783
- const t = e / (1024 * 1024);
784
- return t >= 10 ? `${Math.round(t)}MB` : `${t.toFixed(1)}MB`;
785
- }
786
- function vt(e, n) {
787
- if (!e)
788
- return `mode[${n}]: null`;
789
- let t = `mode[${n}]: ${e.mode}`;
790
- return (e.mode === "forward" || e.mode === "backward") && (e.cycles != null && (t += `, cycles=${e.cycles}`), e.attemptsPerVariant != null && (t += `, attempts=${e.attemptsPerVariant}`)), e.limitTime != null && (t += `, limitTime=${ee(e.limitTime)}`), e.limitTests != null && (t += `, limitTests=${e.limitTests}`), t;
791
- }
792
- function be(e, n) {
793
- const t = e - n, i = t >= 0 ? "+" : "";
794
- return `${H(e)} (${i}${H(t)})`;
795
- }
796
- function Et(e, n) {
797
- if (!e.start)
798
- return;
799
- let t = "[test-variants] start";
800
- n != null && (t += `, memory: ${H(n)}`), e.func("start", t);
801
- }
802
- function xt(e) {
803
- const { options: n, state: t } = e, { logOptions: i, timeController: o } = n;
804
- if (!i.completed)
805
- return;
806
- const a = o.now() - t.startTime;
807
- let r = `[test-variants] end, tests: ${t.tests} (${ee(a)}), async: ${t.iterationsAsync}`;
808
- if (t.startMemory != null) {
809
- const l = Q();
810
- l != null && (r += `, memory: ${be(l, t.startMemory)}`);
811
- }
812
- i.func("completed", r);
813
- }
814
- function ye(e) {
815
- const { options: n, state: t } = e, { logOptions: i } = n, o = t.pendingModeChange;
816
- !i.modeChange || o == null || (i.func(
817
- "modeChange",
818
- `[test-variants] ${vt(o.mode, o.modeIndex)}`
819
- ), t.pendingModeChange = null);
820
- }
821
- function St(e) {
822
- const { options: n, state: t } = e, { logOptions: i, timeController: o } = n, a = o.now();
823
- if (!i.progress || a - t.prevLogTime < i.progress)
824
- return !1;
825
- ye(e);
826
- const r = a - t.startTime;
827
- let l = `[test-variants] tests: ${t.tests} (${ee(r)}), async: ${t.iterationsAsync}`;
828
- if (t.prevLogMemory != null) {
829
- const u = Q();
830
- u != null && (l += `, memory: ${be(u, t.prevLogMemory)}`, t.prevLogMemory = u);
831
- }
832
- return i.func("progress", l), t.prevLogTime = a, !0;
833
- }
834
- function J(e, n) {
835
- e.debugMode = !1, n && (e.iterationsAsync += n.iterationsAsync, e.iterations += n.iterationsSync + n.iterationsAsync);
836
- }
837
- function X(e) {
838
- e.state.debugMode = !0, e.abortControllerParallel.abort(new I());
839
- }
840
- function ve(e, n) {
841
- const { testRun: t, testOptions: i, state: o } = e, a = o.tests;
842
- o.tests++;
843
- try {
844
- const r = t(n, a, i);
845
- if (M(r))
846
- return r.then(
847
- (l) => {
848
- if (!l) {
849
- X(e);
850
- return;
851
- }
852
- J(o, l);
853
- },
854
- (l) => ce(e, n, l, a)
855
- );
856
- if (!r) {
857
- X(e);
858
- return;
859
- }
860
- J(o, r);
861
- } catch (r) {
862
- return r instanceof I ? void 0 : ce(e, n, r, a);
863
- }
864
- }
865
- function wt(e, n) {
866
- const { pool: t, abortSignal: i, testRun: o, testOptionsParallel: a, state: r } = e;
867
- if (!t)
868
- return;
869
- const l = r.tests;
870
- r.tests++, (async () => {
871
- try {
872
- if (i.aborted)
873
- return;
874
- let u = o(n, l, a);
875
- if (M(u) && (u = await u), !u) {
876
- X(e);
877
- return;
878
- }
879
- J(r, u);
880
- } catch (u) {
881
- if (u instanceof I)
882
- return;
883
- ht(e, n, u, l);
884
- } finally {
885
- t.release(1);
886
- }
887
- })();
888
- }
889
- function Ee(e) {
890
- const { options: n, state: t } = e, { logOptions: i, timeController: o, GC_Interval: a } = n;
891
- if (!i.progress && !a)
892
- return;
893
- St(e);
894
- const r = o.now();
895
- if (bt(e, r))
896
- return yt(t, r);
897
- }
898
- function k(e) {
899
- return e.options.abortSignalExternal?.aborted ?? !1;
900
- }
901
- function Z(e) {
902
- return e.abortSignal.aborted;
903
- }
904
- async function W(e, n) {
905
- const { pool: t, state: i, options: o } = e, { parallel: a, logOptions: r } = o;
906
- let l = null;
907
- for (; !k(e); ) {
908
- const u = t && !Z(e);
909
- let c = !1;
910
- u && (t.hold(1) || await se({ pool: t, count: 1, hold: !0 }), c = !0);
911
- try {
912
- if (n != null ? (l = n, n = null) : e.state.debugMode || (l = e.variantsIterator.next()), l == null)
913
- break;
914
- const d = Ee(e);
915
- if (M(d) && await d, k(e))
916
- continue;
917
- if (u)
918
- wt(e, l), c = !1;
919
- else {
920
- r.debug && t && Z(e) && r.func(
921
- "debug",
922
- `[test-variants] parallel aborted, running sequential: tests=${i.tests}`
923
- );
924
- const h = ve(e, l);
925
- M(h) && await h;
926
- }
927
- } finally {
928
- c && t.release(1);
929
- }
930
- }
931
- t && (await se({ pool: t, count: a, hold: !0 }), t.release(a));
932
- }
933
- function Mt(e) {
934
- const { pool: n, state: t, options: i } = e, { logOptions: o } = i;
935
- if (n)
936
- return W(e);
937
- let a = null;
938
- for (; !k(e) && (e.state.debugMode || (a = e.variantsIterator.next()), a != null); ) {
939
- const r = Ee(e);
940
- if (M(r))
941
- return r.then(() => W(e, a));
942
- if (k(e))
943
- continue;
944
- o.debug && Z(e) && o.func(
945
- "debug",
946
- `[test-variants] parallel aborted, running sequential: tests=${t.tests}`
947
- );
948
- const l = ve(e, a);
949
- if (M(l))
950
- return l.then(() => W(e));
951
- }
952
- }
953
- async function It(e, n, t, i) {
954
- const o = pt(i), {
955
- store: a,
956
- logOptions: r,
957
- abortSignalExternal: l,
958
- findBestError: u,
959
- dontThrowIfError: c,
960
- timeController: d,
961
- parallel: h
962
- } = o, y = new ie(), p = new ie(), b = oe(
963
- l,
964
- y.signal
965
- ), E = oe(
966
- b,
967
- p.signal
968
- ), L = {
969
- abortSignal: b,
970
- timeController: d
971
- }, g = {
972
- abortSignal: E,
973
- timeController: d
974
- };
975
- a && await a.replay({
976
- testRun: e,
977
- variantsIterator: n,
978
- testOptions: L,
979
- findBestErrorEnabled: !!u
980
- });
981
- const S = h <= 1 ? null : new Ke(h);
982
- Et(r, t.startMemory);
983
- const V = {
984
- options: o,
985
- testRun: e,
986
- variantsIterator: n,
987
- testOptions: L,
988
- testOptionsParallel: g,
989
- abortControllerGlobal: y,
990
- abortControllerParallel: p,
991
- abortSignal: E,
992
- pool: S,
993
- state: t
994
- };
995
- ye(V);
996
- try {
997
- await Mt(V), E.throwIfAborted();
998
- } catch (P) {
999
- throw y.abort(new I()), P;
1000
- }
1001
- return b.throwIfAborted(), y.abort(new I()), xt(V), await Y(1), mt(t, n, c);
1002
- }
1003
- function Nt(e) {
1004
- return function(t) {
1005
- return async function(o) {
1006
- const a = pe(o?.log), r = st(e, {
1007
- onError: o?.onError,
1008
- log: a,
1009
- pauseDebuggerOnError: o?.pauseDebuggerOnError
1010
- }), l = o?.timeController ?? K, u = Q(), c = nt(l, u), d = o?.onModeChange;
1011
- function h(p) {
1012
- c.pendingModeChange = p, d?.(p);
1013
- }
1014
- const y = dt({
1015
- argsTemplates: t,
1016
- getSeed: o?.getSeed,
1017
- iterationModes: o?.iterationModes,
1018
- equals: o?.findBestError?.equals,
1019
- limitArgOnError: o?.findBestError?.limitArgOnError,
1020
- includeErrorVariant: o?.findBestError?.includeErrorVariant,
1021
- timeController: l,
1022
- onModeChange: h,
1023
- limitCompletionCount: o?.cycles ?? 1,
1024
- limitTests: o?.limitTests,
1025
- limitTime: o?.limitTime
1026
- });
1027
- return It(r, y, c, o);
1028
- };
1029
- };
1030
- }
1031
- export {
1032
- Nt as c
1033
- };