(tc, mods, iterations, initTestObject)
| 563 | * @param {InitTestObjectCallback<T>} [initTestObject] |
| 564 | */ |
| 565 | export const applyRandomTests = (tc, mods, iterations, initTestObject) => { |
| 566 | const gen = tc.prng |
| 567 | const result = init(tc, { users: 5 }, initTestObject) |
| 568 | const { testConnector, users } = result |
| 569 | for (let i = 0; i < iterations; i++) { |
| 570 | if (prng.int32(gen, 0, 100) <= 2) { |
| 571 | // 2% chance to disconnect/reconnect a random user |
| 572 | if (prng.bool(gen)) { |
| 573 | testConnector.disconnectRandom() |
| 574 | } else { |
| 575 | testConnector.reconnectRandom() |
| 576 | } |
| 577 | } else if (prng.int32(gen, 0, 100) <= 1) { |
| 578 | // 1% chance to flush all |
| 579 | testConnector.flushAllMessages() |
| 580 | } else if (prng.int32(gen, 0, 100) <= 50) { |
| 581 | // 50% chance to flush a random message |
| 582 | testConnector.flushRandomMessage() |
| 583 | } |
| 584 | const user = prng.int32(gen, 0, users.length - 1) |
| 585 | const test = prng.oneOf(gen, mods) |
| 586 | test(users[user], gen, result.testObjects[user]) |
| 587 | } |
| 588 | compare(users) |
| 589 | return result |
| 590 | } |
| 591 | |
| 592 | /** |
| 593 | * @typedef {ReturnType<typeof applyRandomTests>} ApplyRandomTestsResult |
no test coverage detected
searching dependent graphs…