@@ -4646,7 +4646,7 @@ public void testGetResolvesToCacheWhenOnlineAndParentListener()
4646
4646
4647
4647
@ Test
4648
4648
public void testGetResolvesToCacheWhenOnlineAndSameLevelListener ()
4649
- throws DatabaseException , InterruptedException {
4649
+ throws DatabaseException , InterruptedException , ExecutionException {
4650
4650
FirebaseApp writeApp =
4651
4651
appForDatabaseUrl (IntegrationTestValues .getDatabaseUrl (), UUID .randomUUID ().toString ());
4652
4652
// To ensure that we don't read the cached results, we need a separate app.
@@ -4658,12 +4658,14 @@ public void testGetResolvesToCacheWhenOnlineAndSameLevelListener()
4658
4658
long val = 34 ;
4659
4659
String writeKey = Objects .requireNonNull (writeDb .getReference ().push ().getKey ());
4660
4660
DatabaseReference writeNode = writeDb .getReference ().child (writeKey );
4661
- writeNode .setValue (val );
4661
+ await ( writeNode .setValue (val ) );
4662
4662
DatabaseReference readNode = readDb .getReference ().child (writeKey );
4663
+ final int testArr [] = {0 };
4663
4664
ValueEventListener listener =
4664
4665
new ValueEventListener () {
4665
4666
@ Override
4666
4667
public void onDataChange (@ NonNull DataSnapshot snapshot ) {
4668
+ assertEquals (0 , testArr [0 ]++);
4667
4669
assertEquals (34L , snapshot .getValue ());
4668
4670
semaphore .release ();
4669
4671
}
@@ -4679,6 +4681,7 @@ public void onCancelled(@NonNull DatabaseError error) {
4679
4681
IntegrationTestHelpers .waitFor (semaphore );
4680
4682
DataSnapshot snapshot = await (readNode .get ());
4681
4683
assertEquals (val , snapshot .getValue ());
4684
+ readNode .removeEventListener (listener );
4682
4685
// need to rewrite it
4683
4686
} catch (ExecutionException e ) {
4684
4687
fail ("get threw an exception: " + e );
@@ -4740,7 +4743,6 @@ public void testGetResolvesToCacheWhenOnlineAndChildLevelListener()
4740
4743
DatabaseReference childReadNode =
4741
4744
readDb .getReference ().child (parentNodeKey ).child (childReadKey );
4742
4745
DatabaseReference childWriteNode = parentWriteNode .child (childReadKey );
4743
-
4744
4746
ValueEventListener listener =
4745
4747
new ValueEventListener () {
4746
4748
@ Override
@@ -4765,6 +4767,7 @@ public void onCancelled(@NonNull DatabaseError error) {
4765
4767
parentWriteNode .setValue (new MapBuilder ().put (childReadKey , val ).build ());
4766
4768
DataSnapshot parentSnapshot = await (childReadNode .get ());
4767
4769
assertEquals (parentSnapshot .getValue (), val );
4770
+ childReadNode .removeEventListener (listener );
4768
4771
} catch (ExecutionException e ) {
4769
4772
fail ("get threw an exception: " + e );
4770
4773
}
0 commit comments