From 818f31fd4c481f69e2fe58ed052c6a5a17f3b6b0 Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Tue, 6 Jun 2023 11:09:54 +0100 Subject: [PATCH 1/8] Make bolt agent an object in intergration tests --- .../src/connection/connection-channel.js | 2 +- .../src/connection/connection.js | 2 +- .../test/internal/connection-channel.test.js | 29 ++++++++++++------- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/bolt-connection/src/connection/connection-channel.js b/packages/bolt-connection/src/connection/connection-channel.js index 10691f5e9..00f028f4d 100644 --- a/packages/bolt-connection/src/connection/connection-channel.js +++ b/packages/bolt-connection/src/connection/connection-channel.js @@ -183,7 +183,7 @@ export default class ChannelConnection extends Connection { /** * Send initialization message. * @param {string} userAgent the user agent for this driver. - * @param {string} boltAgent the bolt agent for this driver. + * @param {Object} boltAgent the bolt agent for this driver. * @param {Object} authToken the object containing auth information. * @param {boolean} waitReAuth whether ot not the connection will wait for re-authentication to happen * @return {Promise} promise resolved with the current connection if connection is successful. Rejected promise otherwise. diff --git a/packages/bolt-connection/src/connection/connection.js b/packages/bolt-connection/src/connection/connection.js index 463c52b8f..f016d2719 100644 --- a/packages/bolt-connection/src/connection/connection.js +++ b/packages/bolt-connection/src/connection/connection.js @@ -90,7 +90,7 @@ export default class Connection { /** * Connect to the target address, negotiate Bolt protocol and send initialization message. * @param {string} userAgent the user agent for this driver. - * @param {string} boltAgent the bolt agent for this driver. + * @param {Object} boltAgent the bolt agent for this driver. * @param {Object} authToken the object containing auth information. * @param {boolean} shouldWaitReAuth whether ot not the connection will wait for re-authentication to happen * @return {Promise} promise resolved with the current connection if connection is successful. Rejected promise otherwise. diff --git a/packages/neo4j-driver/test/internal/connection-channel.test.js b/packages/neo4j-driver/test/internal/connection-channel.test.js index 33cb7a6db..8373391e2 100644 --- a/packages/neo4j-driver/test/internal/connection-channel.test.js +++ b/packages/neo4j-driver/test/internal/connection-channel.test.js @@ -47,6 +47,13 @@ const SUCCESS_MESSAGE = { signature: 0x70, fields: [{}] } const FAILURE_MESSAGE = { signature: 0x7f, fields: [newError('Hello')] } const RECORD_MESSAGE = { signature: 0x71, fields: [{ value: 'Hello' }] } +const BOLT_AGENT = { + product: 'js-driver', + platform: 'SomePlatform', + language: 'js', + languageDetails: 'Some node or deno details' +} + describe('#integration ChannelConnection', () => { /** @type {Connection} */ let connection @@ -104,7 +111,7 @@ describe('#integration ChannelConnection', () => { } connection - .connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('mydriver/0.0.0', BOLT_AGENT, basicAuthToken()) .then(() => { connection .protocol() @@ -177,7 +184,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) connection - .connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('mydriver/0.0.0', BOLT_AGENT, basicAuthToken()) .then(initializedConnection => { expect(initializedConnection).toBe(connection) done() @@ -189,7 +196,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) // wrong port connection - .connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicWrongAuthToken()) + .connect('mydriver/0.0.0', BOLT_AGENT, basicWrongAuthToken()) .then(() => done.fail('Should not initialize')) .catch(error => { expect(error).toBeDefined() @@ -200,7 +207,7 @@ describe('#integration ChannelConnection', () => { it('should have server version after connection initialization completed', async done => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) connection - .connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('mydriver/0.0.0', BOLT_AGENT, basicAuthToken()) .then(initializedConnection => { expect(initializedConnection).toBe(connection) const serverVersion = ServerVersion.fromString(connection.version) @@ -214,7 +221,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) connection - .connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicWrongAuthToken()) + .connect('mydriver/0.0.0', BOLT_AGENT, basicWrongAuthToken()) .then(() => done.fail('Should not connect')) .catch(initialError => { expect(initialError).toBeDefined() @@ -274,7 +281,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) connection - .connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('my-driver/1.2.3', BOLT_AGENT, basicAuthToken()) .then(() => { connection .resetAndFlush() @@ -297,7 +304,7 @@ describe('#integration ChannelConnection', () => { it('should fail to reset and flush when FAILURE received', async done => { createConnection(`bolt://${sharedNeo4j.hostname}`) .then(connection => { - connection.connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken()).then(() => { + connection.connect('my-driver/1.2.3', BOLT_AGENT, basicAuthToken()).then(() => { connection .resetAndFlush() .then(() => done.fail('Should fail')) @@ -325,7 +332,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) connection - .connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('my-driver/1.2.3', BOLT_AGENT, basicAuthToken()) .then(() => { connection .resetAndFlush() @@ -353,7 +360,7 @@ describe('#integration ChannelConnection', () => { createConnection(`bolt://${sharedNeo4j.hostname}`) .then(connection => { connection - .connect('my-driver/1.2.3', 'mydriver/0.0.0 some system info', basicAuthToken()) + .connect('my-driver/1.2.3', BOLT_AGENT, basicAuthToken()) .then(() => { connection.protocol()._responseHandler._currentFailure = newError( 'Hello' @@ -419,7 +426,7 @@ describe('#integration ChannelConnection', () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) recordWrittenMessages(connection._protocol, messages) - await connection.connect('mydriver/0.0.0', 'mydriver/0.0.0 some system info', basicAuthToken()) + await connection.connect('mydriver/0.0.0', BOLT_AGENT, basicAuthToken()) expect(connection.isOpen()).toBeTruthy() await connection.close() @@ -436,7 +443,7 @@ describe('#integration ChannelConnection', () => { it('should not prepare broken connection to close', async () => { connection = await createConnection(`bolt://${sharedNeo4j.hostname}`) - await connection.connect('my-connection/9.9.9', 'mydriver/0.0.0 some system info', basicAuthToken()) + await connection.connect('my-connection/9.9.9', BOLT_AGENT, basicAuthToken()) expect(connection._protocol).toBeDefined() expect(connection._protocol).not.toBeNull() From d0b56a17d51bc1da695735b856d0c22c6ac29553 Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Tue, 6 Jun 2023 12:19:13 +0100 Subject: [PATCH 2/8] More integration test fixes with bolt_agent missing --- packages/neo4j-driver/test/internal/connection-channel.test.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/neo4j-driver/test/internal/connection-channel.test.js b/packages/neo4j-driver/test/internal/connection-channel.test.js index 8373391e2..bf6d6d32d 100644 --- a/packages/neo4j-driver/test/internal/connection-channel.test.js +++ b/packages/neo4j-driver/test/internal/connection-channel.test.js @@ -84,6 +84,7 @@ describe('#integration ChannelConnection', () => { .then(connection => { connection.protocol().initialize({ userAgent: 'mydriver/0.0.0', + boltAgent: BOLT_AGENT, authToken: basicAuthToken(), onComplete: metadata => { expect(metadata).not.toBeNull() @@ -251,7 +252,7 @@ describe('#integration ChannelConnection', () => { it('should not queue INIT observer when broken', done => { testQueueingOfObserversWithBrokenConnection( connection => - connection.protocol().initialize({ userAgent: 'Hello', authToken: {} }), + connection.protocol().initialize({ userAgent: 'Hello', boltAgent: BOLT_AGENT, authToken: {} }), done ) }) From 4cc62773ab995572e418b52d19b5393fa949ed1b Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Tue, 6 Jun 2023 14:22:17 +0100 Subject: [PATCH 3/8] Deno generation --- .../lib/bolt-connection/connection/connection-channel.js | 2 +- .../lib/bolt-connection/connection/connection.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js b/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js index df21b3c59..755b3aeeb 100644 --- a/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js +++ b/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection-channel.js @@ -183,7 +183,7 @@ export default class ChannelConnection extends Connection { /** * Send initialization message. * @param {string} userAgent the user agent for this driver. - * @param {string} boltAgent the bolt agent for this driver. + * @param {Object} boltAgent the bolt agent for this driver. * @param {Object} authToken the object containing auth information. * @param {boolean} waitReAuth whether ot not the connection will wait for re-authentication to happen * @return {Promise} promise resolved with the current connection if connection is successful. Rejected promise otherwise. diff --git a/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection.js b/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection.js index 0913951fa..d80357d09 100644 --- a/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection.js +++ b/packages/neo4j-driver-deno/lib/bolt-connection/connection/connection.js @@ -90,7 +90,7 @@ export default class Connection { /** * Connect to the target address, negotiate Bolt protocol and send initialization message. * @param {string} userAgent the user agent for this driver. - * @param {string} boltAgent the bolt agent for this driver. + * @param {Object} boltAgent the bolt agent for this driver. * @param {Object} authToken the object containing auth information. * @param {boolean} shouldWaitReAuth whether ot not the connection will wait for re-authentication to happen * @return {Promise} promise resolved with the current connection if connection is successful. Rejected promise otherwise. From ae093d8b905c8ddb509464a4ab4ca21cd9b9d370 Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Tue, 6 Jun 2023 15:33:27 +0100 Subject: [PATCH 4/8] Change order of RX returns --- packages/neo4j-driver/test/examples.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neo4j-driver/test/examples.test.js b/packages/neo4j-driver/test/examples.test.js index 273e38d27..f559e0a93 100644 --- a/packages/neo4j-driver/test/examples.test.js +++ b/packages/neo4j-driver/test/examples.test.js @@ -828,8 +828,8 @@ describe('#integration examples', () => { const people = await result.toPromise() expect(people).toEqual([ - Notification.createNext('Infinity Gauntlet'), Notification.createNext('Mjölnir'), + Notification.createNext('Infinity Gauntlet'), Notification.createComplete() ]) }, 60000) From 84bd4fbad2aa808df9140cfd46f54ac6854438d7 Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Wed, 7 Jun 2023 08:51:05 +0100 Subject: [PATCH 5/8] Revert temp test for example integration test --- packages/neo4j-driver/test/examples.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neo4j-driver/test/examples.test.js b/packages/neo4j-driver/test/examples.test.js index f559e0a93..273e38d27 100644 --- a/packages/neo4j-driver/test/examples.test.js +++ b/packages/neo4j-driver/test/examples.test.js @@ -828,8 +828,8 @@ describe('#integration examples', () => { const people = await result.toPromise() expect(people).toEqual([ - Notification.createNext('Mjölnir'), Notification.createNext('Infinity Gauntlet'), + Notification.createNext('Mjölnir'), Notification.createComplete() ]) }, 60000) From c6c1938b1db9b19905a3d38e51fc60e0f665e88d Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Wed, 7 Jun 2023 09:32:52 +0100 Subject: [PATCH 6/8] Fix flakyness in examples.test --- packages/neo4j-driver/test/examples.test.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/neo4j-driver/test/examples.test.js b/packages/neo4j-driver/test/examples.test.js index 273e38d27..1efaec18b 100644 --- a/packages/neo4j-driver/test/examples.test.js +++ b/packages/neo4j-driver/test/examples.test.js @@ -805,8 +805,8 @@ describe('#integration examples', () => { const tempSession = driver.session() try { await tempSession.run( - "UNWIND ['Infinity Gauntlet', 'Mjölnir'] AS item " + - 'CREATE (:Product {id: 0, title: item})' + "UNWIND [{ id: 0, title: 'Infinity Gauntlet'} , { id: 1, title: 'Mjölnir' }] AS item " + + "CREATE (:Product {id: item.id, title: item.title})'" ) } finally { await tempSession.close() @@ -827,11 +827,9 @@ describe('#integration examples', () => { // end::rx-transaction-function[] const people = await result.toPromise() - expect(people).toEqual([ - Notification.createNext('Infinity Gauntlet'), - Notification.createNext('Mjölnir'), - Notification.createComplete() - ]) + expect(people).toContain( + Notification.createNext('Infinity Gauntlet') + ) }, 60000) it('configure transaction timeout', async () => { From bdca43d077c1783a17b09aa331087ecf6dac43fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Barc=C3=A9los?= Date: Wed, 7 Jun 2023 15:52:40 +0200 Subject: [PATCH 7/8] Apply suggestions from code review --- packages/neo4j-driver/test/examples.test.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/neo4j-driver/test/examples.test.js b/packages/neo4j-driver/test/examples.test.js index 1efaec18b..087cbfa42 100644 --- a/packages/neo4j-driver/test/examples.test.js +++ b/packages/neo4j-driver/test/examples.test.js @@ -805,8 +805,8 @@ describe('#integration examples', () => { const tempSession = driver.session() try { await tempSession.run( - "UNWIND [{ id: 0, title: 'Infinity Gauntlet'} , { id: 1, title: 'Mjölnir' }] AS item " + - "CREATE (:Product {id: item.id, title: item.title})'" + "UNWIND ['Infinity Gauntlet', 'Mjölnir'] AS item " + + 'CREATE (:Product {id: 0, title: item})' ) } finally { await tempSession.close() @@ -827,9 +827,16 @@ describe('#integration examples', () => { // end::rx-transaction-function[] const people = await result.toPromise() + expect(titles.length).toEqual(3) expect(people).toContain( Notification.createNext('Infinity Gauntlet') ) + expect(people).toContain( + Notification.createNext('Mjölnir') + ) + expect(people).toContain( + Notification.createComplete() + ) }, 60000) it('configure transaction timeout', async () => { From 9a86f170918ab75a86e4f15ffe31605c0da40b98 Mon Sep 17 00:00:00 2001 From: Conor Watson Date: Wed, 7 Jun 2023 15:27:43 +0100 Subject: [PATCH 8/8] Fix Typo --- packages/neo4j-driver/test/examples.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/neo4j-driver/test/examples.test.js b/packages/neo4j-driver/test/examples.test.js index 087cbfa42..90b56608a 100644 --- a/packages/neo4j-driver/test/examples.test.js +++ b/packages/neo4j-driver/test/examples.test.js @@ -827,7 +827,7 @@ describe('#integration examples', () => { // end::rx-transaction-function[] const people = await result.toPromise() - expect(titles.length).toEqual(3) + expect(people.length).toEqual(3) expect(people).toContain( Notification.createNext('Infinity Gauntlet') )