Skip to content

Make the stress test more reliable #656

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 17, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 70 additions & 30 deletions test/stress.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,32 @@ describe('#integration stress tests', () => {
await driver.close()
})

it('basic', done => {
const context = new Context(driver, LOGGING_ENABLED)
const commands = createCommands(context)
it(
'basic',
done => {
const context = new Context(driver, LOGGING_ENABLED)
const commands = createCommands(context)

console.time('Basic-stress-test')
parallelLimit(commands, TEST_MODE.parallelism, error => {
console.timeEnd('Basic-stress-test')
console.time('Basic-stress-test')
parallelLimit(commands, TEST_MODE.parallelism, error => {
console.timeEnd('Basic-stress-test')

console.log('Read statistics: ', context.readServersWithQueryCount)
console.log('Write statistics: ', context.writeServersWithQueryCount)
console.log('Read statistics: ', context.readServersWithQueryCount)
console.log('Write statistics: ', context.writeServersWithQueryCount)

if (error) {
done.fail(error)
}
if (error) {
done.fail(error)
}

verifyServers(context)
.then(() => verifyNodeCount(context))
.then(() => done())
.catch(error => done.fail(error))
})
})
verifyServers(context)
.then(() => verifyCommandsRun(context, TEST_MODE.commandsCount))
.then(() => verifyNodeCount(context))
.then(() => done())
.catch(error => done.fail(error))
})
},
TEST_MODE.maxRunTimeMs
)

function createCommands (context) {
const uniqueCommands = createUniqueCommands(context)
Expand Down Expand Up @@ -276,7 +281,7 @@ describe('#integration stress tests', () => {
context.log(commandId, 'Query completed successfully')

return session.close().then(() => {
const possibleError = verifyQueryResult(result)
const possibleError = verifyQueryResult(result, context)
callback(possibleError)
})
})
Expand Down Expand Up @@ -316,10 +321,19 @@ describe('#integration stress tests', () => {
context.queryCompleted(result, accessMode, session.lastBookmark())
context.log(commandId, 'Transaction function executed successfully')

return session.close().then(() => {
const possibleError = verifyQueryResult(result)
callback(possibleError)
})
return session
.close()
.then(() => {
const possibleError = verifyQueryResult(result, context)
callback(possibleError)
})
.catch(error => {
context.log(
commandId,
`Error closing the session ${JSON.stringify(error)}`
)
callback(error)
})
})
.catch(error => {
context.log(
Expand Down Expand Up @@ -355,7 +369,7 @@ describe('#integration stress tests', () => {

tx.run(query, params)
.then(result => {
let commandError = verifyQueryResult(result)
let commandError = verifyQueryResult(result, context)

tx.commit()
.catch(commitError => {
Expand Down Expand Up @@ -388,10 +402,13 @@ describe('#integration stress tests', () => {
}
}

function verifyQueryResult (result) {
function verifyQueryResult (result, context) {
if (!result) {
return new Error('Received undefined result')
} else if (result.records.length === 0) {
} else if (
result.records.length === 0 &&
context.writeCommandsRun < TEST_MODE.parallelism
) {
// it is ok to receive no nodes back for read queries at the beginning of the test
return null
} else if (result.records.length === 1) {
Expand Down Expand Up @@ -424,6 +441,14 @@ describe('#integration stress tests', () => {
return null
}

function verifyCommandsRun (context, expectedCommandsRun) {
if (context.commandsRun !== expectedCommandsRun) {
throw new Error(
`Unexpected commands run: ${context.commandsRun}, expected: ${expectedCommandsRun}`
)
}
}

function verifyNodeCount (context) {
const expectedNodeCount = context.createdNodesCount

Expand Down Expand Up @@ -507,10 +532,10 @@ describe('#integration stress tests', () => {

function fetchClusterAddresses (context) {
const session = context.driver.session()
return session.run('CALL dbms.cluster.overview()').then(result =>
session.close().then(() => {
return session
.readTransaction(tx => tx.run('CALL dbms.cluster.overview()'))
.then(result => {
const records = result.records

const supportsMultiDb = protocolVersion >= 4.0
const followers = supportsMultiDb
? addressesForMultiDb(records, 'FOLLOWER')
Expand All @@ -519,9 +544,10 @@ describe('#integration stress tests', () => {
? addressesForMultiDb(records, 'READ_REPLICA')
: addressesWithRole(records, 'READ_REPLICA')

return new ClusterAddresses(followers, readReplicas)
return session
.close()
.then(() => new ClusterAddresses(followers, readReplicas))
})
)
}

function addressesForMultiDb (records, role, db = 'neo4j') {
Expand Down Expand Up @@ -631,6 +657,20 @@ describe('#integration stress tests', () => {
this.protocolVersion = null
}

get commandsRun () {
return [
...Object.values(this.readServersWithQueryCount),
...Object.values(this.writeServersWithQueryCount)
].reduce((a, b) => a + b, 0)
}

get writeCommandsRun () {
return [...Object.values(this.writeServersWithQueryCount)].reduce(
(a, b) => a + b,
0
)
}

queryCompleted (result, accessMode, bookmark) {
const serverInfo = result.summary.server
this.protocolVersion = serverInfo.protocolVersion
Expand Down