implemented random seed generator, in order to reproduce tests

This commit is contained in:
Kevin Jahns
2016-06-29 17:48:56 +02:00
parent 3dc67e075b
commit 2091392031
2 changed files with 27 additions and 2 deletions

View File

@@ -23,6 +23,29 @@ if (typeof global !== 'undefined') {
}
g.g = g
// Helper methods for the random number generator
Math.seedrandom = require('seedrandom')
g.generateRandomSeed = function generateRandomSeed() {
var seed
if (window.location.hash.length > 1) {
seed = window.location.hash.slice(1) // first character is the hash!
console.warn('Using random seed that was specified in the url!')
} else {
seed = JSON.stringify(Math.random())
}
console.info('Using random seed: ' + seed)
setRandomSeed(seed)
}
g.setRandomSeed = function setRandomSeed(seed) {
Math.seedrandom.currentSeed = seed
Math.seedrandom(Math.seedrandom.currentSeed, { global: true })
}
g.generateRandomSeed()
g.YConcurrency_TestingMode = true
jasmine.DEFAULT_TIMEOUT_INTERVAL = 200000
@@ -86,6 +109,7 @@ function getRandomString () {
g.getRandomString = getRandomString
function * applyTransactions (relAmount, numberOfTransactions, objects, users, transactions, noReconnect) {
g.generateRandomSeed() // create a new seed, so we can re-create the behavior
for (var i = 0; i < numberOfTransactions * relAmount + 1; i++) {
var r = Math.random()
if (r > 0.95) {