Skip to content

Commit c22f7a7

Browse files
committed
Implement changes from testkit
1 parent 6faf5c6 commit c22f7a7

File tree

10 files changed

+105
-91
lines changed

10 files changed

+105
-91
lines changed

packages/bolt-connection/src/connection-provider/connection-provider-direct.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {
6666
if (stickyConnection) {
6767
return stickyConnection
6868
}
69+
return connection
6970
}
7071

7172
return new DelegateConnection(connection, databaseSpecificErrorHandler)

packages/bolt-connection/src/connection-provider/connection-provider-routing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
206206
if (stickyConnection) {
207207
return stickyConnection
208208
}
209+
return connection
209210
}
210211

211212
return new DelegateConnection(connection, databaseSpecificErrorHandler)

packages/bolt-connection/test/connection-provider/connection-provider-direct.test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,16 @@ describe('user-switching', () => {
507507
jest.spyOn(pool, 'acquire').mockResolvedValue(connection)
508508
const connectionProvider = newDirectConnectionProvider(address, pool)
509509

510-
const delegatedConnection = await connectionProvider
510+
const acquiredConnection = await connectionProvider
511511
.acquireConnection({
512512
accessMode: 'READ',
513513
database: '',
514514
allowStickyConnection,
515515
auth: acquireAuth
516516
})
517517

518-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
519-
expect(delegatedConnection._delegate).toBe(connection)
520-
expect(connection._sticky).toEqual(false)
518+
expect(acquiredConnection).toBe(connection)
519+
expect(acquiredConnection._sticky).toEqual(false)
521520
})
522521
})
523522
})
@@ -574,17 +573,16 @@ describe('user-switching', () => {
574573
jest.spyOn(pool, 'acquire').mockResolvedValue(connection)
575574
const connectionProvider = newDirectConnectionProvider(address, pool)
576575

577-
const delegatedConnection = await connectionProvider
576+
const acquiredConnection = await connectionProvider
578577
.acquireConnection({
579578
accessMode: 'READ',
580579
database: '',
581580
allowStickyConnection,
582581
auth: acquireAuth
583582
})
584583

585-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
586-
expect(delegatedConnection._delegate).toBe(connection)
587-
expect(connection._sticky).toEqual(false)
584+
expect(acquiredConnection).toBe(connection)
585+
expect(acquiredConnection._sticky).toEqual(false)
588586
})
589587
})
590588
})

packages/bolt-connection/test/connection-provider/connection-provider-routing.test.js

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3487,17 +3487,16 @@ describe.each([
34873487
)
34883488
const auth = acquireAuth
34893489

3490-
const delegatedConnection = await connectionProvider
3490+
const acquiredConnection = await connectionProvider
34913491
.acquireConnection({
34923492
accessMode: 'READ',
34933493
database: '',
34943494
allowStickyConnection,
34953495
auth
34963496
})
34973497

3498-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3499-
expect(delegatedConnection._delegate).toBe(connection)
3500-
expect(connection._sticky).toEqual(false)
3498+
expect(acquiredConnection).toBe(connection)
3499+
expect(acquiredConnection._sticky).toEqual(false)
35013500
})
35023501

35033502
it('should return connection when try switch user on acquire [expired rt]', async () => {
@@ -3530,20 +3529,19 @@ describe.each([
35303529

35313530
const auth = acquireAuth
35323531

3533-
const delegatedConnection = await connectionProvider
3532+
const acquiredConnection = await connectionProvider
35343533
.acquireConnection({
35353534
accessMode: 'READ',
35363535
database: 'dba',
35373536
allowStickyConnection,
35383537
auth
35393538
})
35403539

3541-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3542-
expect(delegatedConnection._delegate).toBe(connection)
3543-
expect(connection._sticky).toEqual(false)
3540+
expect(acquiredConnection).toBe(connection)
3541+
expect(acquiredConnection._sticky).toEqual(false)
35443542
})
35453543

3546-
it('should return delegated connection when try switch user on acquire [expired rt and userSeedRouter]', async () => {
3544+
it('should return connection when try switch user on acquire [expired rt and userSeedRouter]', async () => {
35473545
const address = ServerAddress.fromUrl('localhost:123')
35483546
const pool = newPool()
35493547
const connection = new FakeConnection(address, () => { }, undefined, PROTOCOL_VERSION, null, connAuth, { supportsReAuth: true })
@@ -3575,20 +3573,19 @@ describe.each([
35753573

35763574
const auth = acquireAuth
35773575

3578-
const delegatedConnection = await connectionProvider
3576+
const acquiredConnection = await connectionProvider
35793577
.acquireConnection({
35803578
accessMode: 'READ',
35813579
database: 'dba',
35823580
allowStickyConnection,
35833581
auth
35843582
})
35853583

3586-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3587-
expect(delegatedConnection._delegate).toBe(connection)
3588-
expect(connection._sticky).toEqual(false)
3584+
expect(acquiredConnection).toBe(connection)
3585+
expect(acquiredConnection._sticky).toEqual(false)
35893586
})
35903587

3591-
it('should delegated connection when try switch user on acquire [firstCall and userSeedRouter]', async () => {
3588+
it('should not delegated connection when try switch user on acquire [firstCall and userSeedRouter]', async () => {
35923589
const address = ServerAddress.fromUrl('localhost:123')
35933590
const pool = newPool()
35943591
const connection = new FakeConnection(address, () => { }, undefined, PROTOCOL_VERSION, null, connAuth, { supportsReAuth: true })
@@ -3612,17 +3609,16 @@ describe.each([
36123609

36133610
const auth = acquireAuth
36143611

3615-
const delegatedConnection = await connectionProvider
3612+
const acquiredConnection = await connectionProvider
36163613
.acquireConnection({
36173614
accessMode: 'READ',
36183615
database: 'dba',
36193616
allowStickyConnection,
36203617
auth
36213618
})
36223619

3623-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3624-
expect(delegatedConnection._delegate).toBe(connection)
3625-
expect(connection._sticky).toEqual(false)
3620+
expect(acquiredConnection).toBe(connection)
3621+
expect(acquiredConnection._sticky).toEqual(false)
36263622
})
36273623
})
36283624
})
@@ -3895,17 +3891,16 @@ describe.each([
38953891
)
38963892
const auth = acquireAuth
38973893

3898-
const delegatedConnection = await connectionProvider
3894+
const acquiredConnection = await connectionProvider
38993895
.acquireConnection({
39003896
accessMode: 'READ',
39013897
database: '',
39023898
allowStickyConnection,
39033899
auth
39043900
})
39053901

3906-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3907-
expect(delegatedConnection._delegate).toBe(connection)
3908-
expect(connection._sticky).toEqual(false)
3902+
expect(acquiredConnection).toBe(connection)
3903+
expect(acquiredConnection._sticky).toEqual(false)
39093904
})
39103905

39113906
it('should return connection when try switch user on acquire [expired rt]', async () => {
@@ -3938,20 +3933,19 @@ describe.each([
39383933

39393934
const auth = acquireAuth
39403935

3941-
const delegatedConnection = await connectionProvider
3936+
const acquiredConnection = await connectionProvider
39423937
.acquireConnection({
39433938
accessMode: 'READ',
39443939
database: 'dba',
39453940
allowStickyConnection,
39463941
auth
39473942
})
39483943

3949-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3950-
expect(delegatedConnection._delegate).toBe(connection)
3951-
expect(connection._sticky).toEqual(false)
3944+
expect(acquiredConnection).toBe(connection)
3945+
expect(acquiredConnection._sticky).toEqual(false)
39523946
})
39533947

3954-
it('should return delegated connection when try switch user on acquire [expired rt and userSeedRouter]', async () => {
3948+
it('should return connection when try switch user on acquire [expired rt and userSeedRouter]', async () => {
39553949
const address = ServerAddress.fromUrl('localhost:123')
39563950
const pool = newPool()
39573951
const connection = new FakeConnection(address, () => { }, undefined, PROTOCOL_VERSION, null, connAuth, { supportsReAuth: true })
@@ -3983,20 +3977,19 @@ describe.each([
39833977

39843978
const auth = acquireAuth
39853979

3986-
const delegatedConnection = await connectionProvider
3980+
const acquiredConnection = await connectionProvider
39873981
.acquireConnection({
39883982
accessMode: 'READ',
39893983
database: 'dba',
39903984
allowStickyConnection,
39913985
auth
39923986
})
39933987

3994-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
3995-
expect(delegatedConnection._delegate).toBe(connection)
3996-
expect(connection._sticky).toEqual(false)
3988+
expect(acquiredConnection).toBe(connection)
3989+
expect(acquiredConnection._sticky).toEqual(false)
39973990
})
39983991

3999-
it('should delegated connection when try switch user on acquire [firstCall and userSeedRouter]', async () => {
3992+
it('should not delegated connection when try switch user on acquire [firstCall and userSeedRouter]', async () => {
40003993
const address = ServerAddress.fromUrl('localhost:123')
40013994
const pool = newPool()
40023995
const connection = new FakeConnection(address, () => { }, undefined, PROTOCOL_VERSION, null, connAuth, { supportsReAuth: true })
@@ -4020,17 +4013,16 @@ describe.each([
40204013

40214014
const auth = acquireAuth
40224015

4023-
const delegatedConnection = await connectionProvider
4016+
const acquiredConnection = await connectionProvider
40244017
.acquireConnection({
40254018
accessMode: 'READ',
40264019
database: 'dba',
40274020
allowStickyConnection,
40284021
auth
40294022
})
40304023

4031-
expect(delegatedConnection).toBeInstanceOf(DelegateConnection)
4032-
expect(delegatedConnection._delegate).toBe(connection)
4033-
expect(connection._sticky).toEqual(false)
4024+
expect(acquiredConnection).toBe(connection)
4025+
expect(acquiredConnection._sticky).toEqual(false)
40344026
})
40354027
})
40364028
})

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-direct.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export default class DirectConnectionProvider extends PooledConnectionProvider {
6666
if (stickyConnection) {
6767
return stickyConnection
6868
}
69+
return connection
6970
}
7071

7172
return new DelegateConnection(connection, databaseSpecificErrorHandler)

packages/neo4j-driver-deno/lib/bolt-connection/connection-provider/connection-provider-routing.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export default class RoutingConnectionProvider extends PooledConnectionProvider
206206
if (stickyConnection) {
207207
return stickyConnection
208208
}
209+
return connection
209210
}
210211

211212
return new DelegateConnection(connection, databaseSpecificErrorHandler)

packages/testkit-backend/src/context.js

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ export default class Context {
1212
this._bookmarkSupplierRequests = {}
1313
this._notifyBookmarksRequests = {}
1414
this._bookmarksManagers = {}
15-
this._authTokenProviders = {}
16-
this._authTokenProviderRequests = {}
15+
this._authTokenManagers = {}
16+
this._authTokenManagerGetAuthRequests = {}
17+
this._authTokenManagerOnAuthExpiredRequests = {}
1718
this._binder = binder
1819
this._environmentLogLevel = environmentLogLevel
1920
}
@@ -163,32 +164,40 @@ export default class Context {
163164
delete this._bookmarksManagers[id]
164165
}
165166

166-
addAuthTokenProvider (authTokenProviderFactory) {
167+
addAuthTokenManager (authTokenManagersFactory) {
167168
this._id++
168-
this._authTokenProviders[this._id] = authTokenProviderFactory(this._id)
169+
this._authTokenManagers[this._id] = authTokenManagersFactory(this._id)
169170
return this._id
170171
}
171172

172-
getAuthTokenProvider (id) {
173-
return this._authTokenProviders[id]
173+
getAuthTokenManager (id) {
174+
return this._authTokenManagers[id]
174175
}
175176

176-
removeAuthTokenProvider (id) {
177-
delete this._authTokenProviders[id]
177+
removeAuthTokenManager (id) {
178+
delete this._authTokenManagers[id]
178179
}
179180

180-
addAuthTokenProviderRequest (resolve, reject) {
181-
return this._add(this._authTokenProviderRequests, {
181+
addAuthTokenManagerGetAuthRequest (resolve, reject) {
182+
return this._add(this._authTokenManagerGetAuthRequests, {
182183
resolve, reject
183184
})
184185
}
185186

186-
removeAuthTokenProviderRequest (id) {
187-
delete this._authTokenProviderRequests[id]
187+
getAuthTokenManagerGetAuthRequest (id) {
188+
return this._authTokenManagerGetAuthRequests[id]
188189
}
189190

190-
getAuthTokenProviderRequest (id) {
191-
return this._authTokenProviderRequests[id]
191+
removeAuthTokenManagerGetAuthRequest (id) {
192+
delete this._authTokenManagerGetAuthRequests[id]
193+
}
194+
195+
addAuthTokenManagerOnAuthExpiredRequest (request) {
196+
return this._add(this._authTokenManagerOnAuthExpiredRequests, request)
197+
}
198+
199+
removeAuthTokenManagerOnAuthExpiredRequest (id) {
200+
delete this._authTokenManagerOnAuthExpiredRequests[id]
192201
}
193202

194203
_add (map, object) {

packages/testkit-backend/src/request-handlers-rx.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ export {
2525
BookmarksConsumerCompleted,
2626
StartSubTest,
2727
ExecuteQuery,
28-
NewAuthTokenProvider,
29-
AuthTokenProviderCompleted,
30-
AuthTokenProviderClose,
28+
NewAuthTokenManager,
29+
AuthTokenManagerClose,
30+
AuthTokenManagerGetAuthCompleted,
31+
AuthTokenManagerOnAuthExpiredCompleted,
3132
FakeTimeInstall,
3233
FakeTimeTick,
3334
FakeTimeUninstall

0 commit comments

Comments
 (0)