anchor.diff:        });
   
         schedule(() {
  -        return testRef.push(value: 3);
  -      });
  -
  -      schedule(() {
  -        expect(eventCount, 3);
  +        Future waitFuture = subscription.cancel();
  +        if (waitFuture == null) {
  +          return testRef.push(value: 3);
  +        }
  +        else waitFuture.then((_) {
  +          return testRef.push(value: 3);
  +        });
         });
       });
   
       test('onChildChanged', () {
         Firebase testRef;
  +      StreamSubscription<Event> subscription;
         var eventCount = 0;
   
         schedule(() {
           testRef = f.child('onChildChanged');
  -        testRef.onChildChanged.listen((event) {
  +        subscription = testRef.onChildChanged.listen((event) {
             var ss = event.snapshot;
             expect(ss.name, 'key');
             eventCount++;
  
positive.code:     });
    });
  
    group('on', () {
  
      test('onChildAdded', () {
        Firebase testRef;
        var eventCount = 0;
  
        schedule(() {
          testRef = f.child('onChildAdded');
          testRef.onChildAdded.listen((event) {
            var ss = event.snapshot;
            eventCount++;
            expect(ss.val(), eventCount);
          });
  
  
negative.code:       });
  
        schedule(() {
          Future waitFuture = subscription.cancel();
          if (waitFuture == null) {
            return testRef.set({'key': 3});
          }
          else waitFuture.then((_) {
            return testRef.set({'key': 3});
          });
        });
  
        schedule(() {
          expect(eventCount, 2);
        });
      });
  
      test('onChildRemoved', () {
        Firebase testRef;
        StreamSubscription<Event> onChildRemovedSubscription;
        int childRemovedCount = 0;
  
        schedule(() {
          testRef = f.child('onChildAdded');
          onChildRemovedSubscription = testRef.onChildRemoved.listen((event) {
            var ss = event.snapshot;
            expect(++childRemovedCount, 1);
            expect(ss.name, addedKeys[0]);
          });
  
          return testRef.child(addedKeys[0]).remove();
        });
  
        schedule(() {
          Future waitFuture = onChildRemovedSubscription.cancel();
          if (waitFuture == null) {
            return testRef.child(addedKeys[1]).remove();
          }
          else waitFuture.then((_) {
            return testRef.child(addedKeys[1]).remove();
          });
        });
      });
  
      test('onValue', () {
        Firebase testRef;
        StreamSubscription<Event> onValueSubscription;
        int valueCount = 0;
  
        schedule(() {
          testRef = f.child('onValue');
          onValueSubscription = testRef.onValue.listen((event) {
            var ss = event.snapshot;
            expect(ss.name, 'onValue');
            expect(ss.val(), {'key': ++valueCount});
            expect(valueCount, lessThan(3));
          });
          return testRef.set({'key': 1});
        });
  
        schedule(() {
          return testRef.update({'key': 2});
        });
  
        schedule(() {
          Future waitFuture = onValueSubscription.cancel();
          if (waitFuture == null) {
            return testRef.update({'key': 3});
          }
          else waitFuture.then((_) {
            return testRef.update({'key': 3});
          });
        });
      });
  
    });
  
    group('once', () {
  