@@ -32,6 +32,20 @@ import firebase from '@firebase/app';
32
32
import '../index' ;
33
33
34
34
describe ( 'Transaction Tests' , function ( ) {
35
+ // Tests that use hijackHash() should set restoreHash to the restore function
36
+ // and be sure to call it (and set restoreHash back to null) before the test
37
+ // exits. In the case that the test fails to do so, we'll log a warning and
38
+ // call restoreHash() manually to ensure subsequent tests aren't affected.
39
+ let restoreHash = null ;
40
+
41
+ afterEach ( ( ) => {
42
+ if ( restoreHash ) {
43
+ console . warn ( "Prior test didn't properly call restoreHash()!" ) ;
44
+ restoreHash ( ) ;
45
+ restoreHash = null ;
46
+ }
47
+ } ) ;
48
+
35
49
it ( 'New value is immediately visible.' , function ( ) {
36
50
const node = getRandomNode ( ) as Reference ;
37
51
node . child ( 'foo' ) . transaction ( function ( ) {
@@ -45,7 +59,7 @@ describe('Transaction Tests', function() {
45
59
expect ( val ) . to . equal ( 42 ) ;
46
60
} ) ;
47
61
48
- it . skip ( 'Event is raised for new value.' , function ( ) {
62
+ it ( 'Event is raised for new value.' , function ( ) {
49
63
const node = getRandomNode ( ) as Reference ;
50
64
const fooNode = node . child ( 'foo' ) ;
51
65
const eventHelper = eventTestHelper ( [ [ fooNode , [ 'value' , '' ] ] ] ) ;
@@ -475,7 +489,7 @@ describe('Transaction Tests', function() {
475
489
} ) ;
476
490
477
491
it ( 'Transaction aborts after 25 retries.' , function ( done ) {
478
- const restoreHash = hijackHash ( function ( ) {
492
+ restoreHash = hijackHash ( function ( ) {
479
493
return 'duck, duck, goose.' ;
480
494
} ) ;
481
495
@@ -492,6 +506,7 @@ describe('Transaction Tests', function() {
492
506
expect ( committed ) . to . equal ( false ) ;
493
507
expect ( tries ) . to . equal ( 25 ) ;
494
508
restoreHash ( ) ;
509
+ restoreHash = null ;
495
510
done ( ) ;
496
511
}
497
512
) ;
@@ -526,7 +541,7 @@ describe('Transaction Tests', function() {
526
541
const node = getRandomNode ( ) as Reference ;
527
542
let fooTransactionDone = false ;
528
543
let barTransactionDone = false ;
529
- const restoreHash = hijackHash ( function ( ) {
544
+ restoreHash = hijackHash ( function ( ) {
530
545
return 'foobar' ;
531
546
} ) ;
532
547
@@ -569,6 +584,7 @@ describe('Transaction Tests', function() {
569
584
expect ( fooTransactionDone ) . to . equal ( true ) ;
570
585
expect ( barTransactionDone ) . to . equal ( false ) ;
571
586
restoreHash ( ) ;
587
+ restoreHash = null ;
572
588
} ) ;
573
589
574
590
it ( 'Test transaction on wacky unicode data.' , function ( done ) {
@@ -793,11 +809,14 @@ describe('Transaction Tests', function() {
793
809
794
810
// This test is meant to ensure that with applyLocally=false, while the transaction is outstanding, we continue
795
811
// to get events from other clients.
796
- it ( 'Transaction without local events (2)' , function ( done ) {
812
+ // TODO(mikelehen): Unfortunately this test is currently flaky. It's inherently a racey test since it's
813
+ // trying to do 4 sets before the transaction retries 25 times (and fails), using two different connections.
814
+ // Disabling for now until we rework the approach.
815
+ it . skip ( 'Transaction without local events (2)' , function ( done ) {
797
816
const refPair = getRandomNode ( 2 ) as Reference [ ] ,
798
817
ref1 = refPair [ 0 ] ,
799
818
ref2 = refPair [ 1 ] ;
800
- const restoreHash = hijackHash ( function ( ) {
819
+ restoreHash = hijackHash ( function ( ) {
801
820
return 'badhash' ;
802
821
} ) ;
803
822
const SETS = 4 ;
@@ -818,6 +837,7 @@ describe('Transaction Tests', function() {
818
837
819
838
if ( current === SETS - 1 ) {
820
839
restoreHash ( ) ;
840
+ restoreHash = null ;
821
841
}
822
842
return 'txn result' ;
823
843
} ,
@@ -856,7 +876,10 @@ describe('Transaction Tests', function() {
856
876
}
857
877
expect ( events [ SETS ] ) . to . equal ( 'txn result' ) ;
858
878
859
- restoreHash ( ) ;
879
+ if ( restoreHash ) {
880
+ restoreHash ( ) ;
881
+ restoreHash = null ;
882
+ }
860
883
done ( ) ;
861
884
} ) ;
862
885
}
0 commit comments