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

@ -42,6 +42,7 @@
},
"homepage": "http://y-js.org",
"devDependencies": {
"babel-eslint": "^5.0.0-beta6",
"babel-plugin-transform-runtime": "^6.1.18",
"babel-preset-es2015": "^6.1.18",
"babelify": "^7.2.0",
@ -69,10 +70,10 @@
"pre-commit": "^1.1.1",
"regenerator": "^0.8.42",
"run-sequence": "^1.1.4",
"seedrandom": "^2.4.2",
"standard": "^5.2.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0",
"babel-eslint": "^5.0.0-beta6"
"vinyl-source-stream": "^1.1.0"
},
"dependencies": {}
}

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) {