Skip to content

Commit f2ec9d3

Browse files
Prevent 5.0 flakyness from async db creation (#1786)
* Add util fn for properly creating databases to avoid flakyness from slow database creations * Run run multidb tests only on dbs with full SHOW DATABASE command
1 parent e47b949 commit f2ec9d3

File tree

5 files changed

+44
-37
lines changed

5 files changed

+44
-37
lines changed

e2e_tests/integration/connect-form.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('Connect form', () => {
113113
})
114114
}
115115
}
116-
if (Cypress.config('serverVersion') >= 4.0) {
116+
if (Cypress.config('serverVersion') >= 4.1) {
117117
it('can connect with the neo4j:// scheme', () => {
118118
cy.executeCommand(':clear')
119119
const boltUrl = 'neo4j://' + stripScheme(Cypress.config('boltUrl'))
@@ -125,10 +125,7 @@ describe('Connect form', () => {
125125
it('shows correct metadata when using db field', () => {
126126
cy.connect('neo4j', Cypress.config('password'))
127127
cy.executeCommand(':use system')
128-
cy.executeCommand('DROP DATABASE sidebartest IF EXISTS')
129-
cy.executeCommand('CREATE DATABASE sidebartest')
130-
cy.wait(10000) // Wait for db to come online
131-
cy.contains('1 system update, no records')
128+
cy.createDatabase('sidebartest')
132129
cy.executeCommand(':use sidebartest')
133130
cy.executeCommand('create (:TestLabel)')
134131
cy.executeCommand(':use neo4j')

e2e_tests/integration/multi-db.spec.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ describe('Multi database', () => {
4040
before(() => {
4141
cy.visit(Cypress.config('url')).title().should('include', 'Neo4j Browser')
4242
cy.wait(3000)
43+
cy.ensureConnection()
4344
})
44-
it('can connect', () => {
45-
const password = Cypress.config('password')
46-
cy.connect('neo4j', password)
47-
})
48-
if (Cypress.config('serverVersion') >= 4.0) {
45+
46+
if (Cypress.config('serverVersion') >= 4.1) {
4947
if (isEnterpriseEdition()) {
5048
it('shows a message indicating whether system updates have occurred', () => {
49+
cy.executeCommand('DROP DATABASE test1 IF EXISTS')
5150
cy.executeCommand(':clear')
5251

5352
cy.executeCommand(':use system')
@@ -94,10 +93,7 @@ describe('Multi database', () => {
9493
it('adds databases to the sidebar and adds backticks to special db names', () => {
9594
// Add db
9695
cy.executeCommand(':use system')
97-
cy.executeCommand('CREATE DATABASE `name-with-dash`')
98-
cy.resultContains('1 system update')
99-
cy.wait(10000) // wait for db to come online
100-
cy.executeCommand(':clear')
96+
cy.createDatabase('`name-with-dash`')
10197

10298
// Count items in list
10399
cy.get('[data-testid="navigationDBMS"]').click()
@@ -178,11 +174,8 @@ describe('Multi database', () => {
178174

179175
if (isEnterpriseEdition()) {
180176
it('lists new databases with :dbs command', () => {
181-
cy.executeCommand('CREATE DATABASE sidebartest')
177+
cy.createDatabase('sidebartest')
182178

183-
cy.wait(3000) // CREATE database can take a sec
184-
185-
cy.executeCommand(':clear')
186179
cy.executeCommand(':dbs')
187180
databaseList().should('have.length', 3)
188181
databaseList().contains('system')

e2e_tests/integration/multistatements.spec.ts

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('Multi statements', () => {
112112
.first()
113113
.should('contain', 'ERROR')
114114
})
115-
if (Cypress.config('serverVersion') >= 4.0) {
115+
if (Cypress.config('serverVersion') >= 4.1) {
116116
if (isEnterpriseEdition()) {
117117
it('Can use :use command in multi-statements', () => {
118118
cy.executeCommand(':clear')
@@ -122,25 +122,9 @@ describe('Multi statements', () => {
122122
'have.length',
123123
1
124124
)
125-
cy.executeCommand('DROP DATABASE test1')
126-
cy.executeCommand('DROP DATABASE test2')
127-
cy.get('[data-testid="frame"]', { timeout: 10000 }).should(
128-
'have.length',
129-
3
130-
)
131-
cy.executeCommand(':clear')
132125

133-
cy.executeCommand('CREATE DATABASE test1')
134-
cy.get('[data-testid="frame"]', { timeout: 10000 }).should(
135-
'have.length',
136-
1
137-
)
138-
cy.executeCommand('CREATE DATABASE test2')
139-
cy.get('[data-testid="frame"]', { timeout: 10000 }).should(
140-
'have.length',
141-
2
142-
)
143-
cy.executeCommand(':clear')
126+
cy.createDatabase('test1')
127+
cy.createDatabase('test2')
144128

145129
// Time to try it
146130
const query = ':use test1; CREATE(:Test1); :use test2; CREATE(:Test2);'

e2e_tests/support/commands.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,32 @@ Cypress.Commands.add(
189189
})
190190
}
191191
)
192+
193+
Cypress.Commands.add('createDatabase', (dbName: string) => {
194+
cy.executeCommand(`DROP DATABASE ${dbName} IF EXISTS;`)
195+
cy.executeCommand(':clear')
196+
cy.executeCommand(`CREATE DATABASE ${dbName}`)
197+
cy.contains('1 system update, no records')
198+
199+
pollForDbOnline()
200+
201+
function pollForDbOnline(totalWaitMs = 0) {
202+
if (totalWaitMs > 6000) {
203+
throw new Error('Database did not come online')
204+
}
205+
206+
cy.get('[data-testid="frameCommand"]').click()
207+
cy.typeInFrame(`SHOW DATABASE ${dbName} YIELD currentStatus{enter}`)
208+
cy.get('[data-testid="frameContents"] [role="cell"] span').then(
209+
statusSpan => {
210+
if (statusSpan.text().includes('online')) {
211+
// started properly, clear stream & carry on.
212+
cy.executeCommand(':clear')
213+
} else {
214+
cy.wait(500)
215+
pollForDbOnline(totalWaitMs + 500)
216+
}
217+
}
218+
)
219+
}
220+
})

e2e_tests/support/global.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ declare global {
4444
options?: Partial<Cypress.TypeOptions>
4545
): Cypress.Chainable<void>
4646
waitForCommandResult(): Cypress.Chainable<void>
47+
/**
48+
* Custom command to create a database and wait for it to come online
49+
*/
50+
createDatabase(dbName: string): Cypress.Chainable<void>
4751
/**
4852
* Custom command for testing content of frame
4953
*/

0 commit comments

Comments
 (0)