@@ -62,6 +62,8 @@ func TestSession(st *testing.T) {
62
62
return & router , & pool , sess
63
63
}
64
64
65
+ tokenExpiredErr := & db.Neo4jError {Code : "Neo.ClientError.Security.TokenExpired" , Msg : "oopsie whoopsie" }
66
+
65
67
st .Run ("Retry mechanism" , func (rt * testing.T ) {
66
68
// Checks that retries occur on database error and that it stops retrying after a certain
67
69
// amount of time and that connections are returned to pool upon failure.
@@ -141,17 +143,17 @@ func TestSession(st *testing.T) {
141
143
dirtyBookmarks := []string {"" , "b1" , "" , "b2" , "" }
142
144
cleanBookmarks := []string {"b1" , "b2" }
143
145
_ , pool , sess := createSessionWithBookmarks (dirtyBookmarks )
144
- conn := & ConnFake {Alive : true , Err : errors .New ("Make all fail" )}
146
+ err := errors .New ("make all fail" )
147
+ conn := & ConnFake {Alive : true , RunErr : err , TxBeginErr : err }
145
148
pool .BorrowConn = conn
146
149
147
- // All of these assume that Err on ConnFake fails the operations
148
150
sess .Run ("cypher" , nil )
149
151
sess .BeginTransaction ()
150
152
sess .ReadTransaction (func (tx Transaction ) (interface {}, error ) {
151
- return nil , errors .New ("somehting " )
153
+ return nil , errors .New ("something " )
152
154
})
153
155
sess .WriteTransaction (func (tx Transaction ) (interface {}, error ) {
154
- return nil , errors .New ("somehting " )
156
+ return nil , errors .New ("something " )
155
157
})
156
158
AssertLen (t , conn .RecordedTxs , 4 )
157
159
for _ , rtx := range conn .RecordedTxs {
@@ -297,6 +299,98 @@ func TestSession(st *testing.T) {
297
299
_ , err = sess .Run ("cypher" , nil )
298
300
assertUsageError (t , err )
299
301
})
302
+
303
+ bt .Run ("Token expiration in session run after errored connection acquisition" , func (t * testing.T ) {
304
+ _ , pool , sess := createSession ()
305
+ pool .BorrowErr = tokenExpiredErr
306
+
307
+ _ , err := sess .Run ("cypher" , map [string ]interface {}{})
308
+
309
+ assertTokenExpiredError (t , err )
310
+ })
311
+
312
+ bt .Run ("Token expiration after run" , func (t * testing.T ) {
313
+ _ , pool , sess := createSession ()
314
+ conn := & ConnFake {Alive : true , RunErr : tokenExpiredErr }
315
+ pool .BorrowConn = conn
316
+
317
+ _ , err := sess .Run ("cypher" , map [string ]interface {}{})
318
+
319
+ assertTokenExpiredError (t , err )
320
+ })
321
+
322
+ bt .Run ("Token expiration after result collect call" , func (t * testing.T ) {
323
+ _ , pool , sess := createSession ()
324
+ conn := & ConnFake {Alive : true , Nexts : []Next {{Err : tokenExpiredErr }}}
325
+ pool .BorrowConn = conn
326
+
327
+ result , err := sess .Run ("cypher" , map [string ]interface {}{})
328
+ AssertNil (t , err )
329
+ _ , err = result .Collect ()
330
+
331
+ assertTokenExpiredError (t , err )
332
+ })
333
+
334
+ bt .Run ("Token expiration after result consume call" , func (t * testing.T ) {
335
+ _ , pool , sess := createSession ()
336
+ conn := & ConnFake {Alive : true , ConsumeErr : tokenExpiredErr }
337
+ pool .BorrowConn = conn
338
+
339
+ result , err := sess .Run ("cypher" , map [string ]interface {}{})
340
+ AssertNil (t , err )
341
+ _ , err = result .Consume ()
342
+
343
+ assertTokenExpiredError (t , err )
344
+ })
345
+
346
+ bt .Run ("Token expiration after result consume next and err call" , func (t * testing.T ) {
347
+ _ , pool , sess := createSession ()
348
+ conn := & ConnFake {Alive : true , Nexts : []Next {{Err : tokenExpiredErr }}}
349
+ pool .BorrowConn = conn
350
+
351
+ result , err := sess .Run ("cypher" , map [string ]interface {}{})
352
+ AssertNil (t , err )
353
+ _ = result .Next ()
354
+ err = result .Err ()
355
+
356
+ assertTokenExpiredError (t , err )
357
+ })
358
+
359
+ bt .Run ("Token expiration after result single record extraction" , func (t * testing.T ) {
360
+ _ , pool , sess := createSession ()
361
+ conn := & ConnFake {Alive : true , Nexts : []Next {{Err : tokenExpiredErr }}}
362
+ pool .BorrowConn = conn
363
+
364
+ result , err := sess .Run ("cypher" , map [string ]interface {}{})
365
+ AssertNil (t , err )
366
+ _ , err = result .Single ()
367
+
368
+ assertTokenExpiredError (t , err )
369
+ })
370
+
371
+ bt .Run ("Token expiration after write transaction function" , func (t * testing.T ) {
372
+ _ , pool , sess := createSession ()
373
+ conn := & ConnFake {Alive : true }
374
+ pool .BorrowConn = conn
375
+
376
+ _ , err := sess .WriteTransaction (func (tx Transaction ) (interface {}, error ) {
377
+ return nil , tokenExpiredErr
378
+ })
379
+
380
+ assertTokenExpiredError (t , err )
381
+ })
382
+
383
+ bt .Run ("Token expiration after read transaction function" , func (t * testing.T ) {
384
+ _ , pool , sess := createSession ()
385
+ conn := & ConnFake {Alive : true }
386
+ pool .BorrowConn = conn
387
+
388
+ _ , err := sess .ReadTransaction (func (tx Transaction ) (interface {}, error ) {
389
+ return nil , tokenExpiredErr
390
+ })
391
+
392
+ assertTokenExpiredError (t , err )
393
+ })
300
394
})
301
395
302
396
st .Run ("Explicit transaction" , func (bt * testing.T ) {
@@ -342,6 +436,57 @@ func TestSession(st *testing.T) {
342
436
_ , err := sess .BeginTransaction ()
343
437
AssertNoError (t , err )
344
438
})
439
+
440
+ bt .Run ("Token expiration after transaction begin" , func (t * testing.T ) {
441
+ _ , pool , sess := createSession ()
442
+ conn := & ConnFake {Alive : true , TxBeginErr : tokenExpiredErr }
443
+ pool .BorrowConn = conn
444
+
445
+ tx , err := sess .BeginTransaction ()
446
+
447
+ AssertNil (t , tx )
448
+ assertTokenExpiredError (t , err )
449
+ })
450
+
451
+ bt .Run ("Token expiration after transaction run" , func (t * testing.T ) {
452
+ _ , pool , sess := createSession ()
453
+ conn := & ConnFake {Alive : true , RunTxErr : tokenExpiredErr }
454
+ pool .BorrowConn = conn
455
+
456
+ tx , err := sess .BeginTransaction ()
457
+ AssertNil (t , err )
458
+ _ , err = tx .Run ("cypher" , map [string ]interface {}{})
459
+
460
+ assertTokenExpiredError (t , err )
461
+ })
462
+
463
+ bt .Run ("Token expiration after transaction commit" , func (t * testing.T ) {
464
+ _ , pool , sess := createSession ()
465
+ conn := & ConnFake {Alive : true , TxCommitErr : tokenExpiredErr }
466
+ pool .BorrowConn = conn
467
+
468
+ tx , err := sess .BeginTransaction ()
469
+ AssertNil (t , err )
470
+ _ , err = tx .Run ("cypher" , map [string ]interface {}{})
471
+ AssertNil (t , err )
472
+ err = tx .Commit ()
473
+
474
+ assertTokenExpiredError (t , err )
475
+ })
476
+
477
+ bt .Run ("Token expiration after transaction rollback" , func (t * testing.T ) {
478
+ _ , pool , sess := createSession ()
479
+ conn := & ConnFake {Alive : true , TxRollbackErr : tokenExpiredErr }
480
+ pool .BorrowConn = conn
481
+
482
+ tx , err := sess .BeginTransaction ()
483
+ AssertNil (t , err )
484
+ _ , err = tx .Run ("cypher" , map [string ]interface {}{})
485
+ AssertNil (t , err )
486
+ err = tx .Rollback ()
487
+
488
+ assertTokenExpiredError (t , err )
489
+ })
345
490
})
346
491
347
492
st .Run ("Close" , func (ct * testing.T ) {
@@ -367,3 +512,9 @@ func TestSession(st *testing.T) {
367
512
})
368
513
})
369
514
}
515
+
516
+ func assertTokenExpiredError (t * testing.T , err error ) {
517
+ AssertSameType (t , err , & TokenExpiredError {})
518
+ AssertErrorMessageContains (t , err , "Neo.ClientError.Security.TokenExpired" )
519
+ AssertErrorMessageContains (t , err , "oopsie whoopsie" )
520
+ }
0 commit comments