MCPcopy
hub / github.com/yjs/yjs / applyRandomTests

Function applyRandomTests

tests/testHelper.js:565–590  ·  view source on GitHub ↗
(tc, mods, iterations, initTestObject)

Source from the content-addressed store, hash-verified

563 * @param {InitTestObjectCallback<T>} [initTestObject]
564 */
565export 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

Calls 6

initFunction · 0.85
compareFunction · 0.85
disconnectRandomMethod · 0.80
reconnectRandomMethod · 0.80
flushAllMessagesMethod · 0.80
flushRandomMessageMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…