Skip to content

Make bolt agent an object in integration tests #1092

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 8 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
Expand Down
2 changes: 1 addition & 1 deletion packages/bolt-connection/src/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Connection>} promise resolved with the current connection if connection is successful. Rejected promise otherwise.
Expand Down
15 changes: 10 additions & 5 deletions packages/neo4j-driver/test/examples.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -806,7 +806,7 @@ describe('#integration examples', () => {
try {
await tempSession.run(
"UNWIND ['Infinity Gauntlet', 'Mjölnir'] AS item " +
'CREATE (:Product {id: 0, title: item})'
'CREATE (:Product {id: 0, title: item})'
)
} finally {
await tempSession.close()
Expand All @@ -827,11 +827,16 @@ describe('#integration examples', () => {
// end::rx-transaction-function[]

const people = await result.toPromise()
expect(people).toEqual([
Notification.createNext('Infinity Gauntlet'),
Notification.createNext('Mjölnir'),
expect(people.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 () => {
Expand Down
32 changes: 20 additions & 12 deletions packages/neo4j-driver/test/internal/connection-channel.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,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()
Expand Down Expand Up @@ -104,7 +112,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()
Expand Down Expand Up @@ -177,7 +185,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()
Expand All @@ -189,7 +197,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()
Expand All @@ -200,7 +208,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)
Expand All @@ -214,7 +222,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()
Expand Down Expand Up @@ -244,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
)
})
Expand Down Expand Up @@ -274,7 +282,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()
Expand All @@ -297,7 +305,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'))
Expand Down Expand Up @@ -325,7 +333,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()
Expand Down Expand Up @@ -353,7 +361,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'
Expand Down Expand Up @@ -419,7 +427,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()
Expand All @@ -436,7 +444,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()

Expand Down