Ember Observers getting broken

93 Views Asked by At

We have a complex app and we do write test cases for testing.

While writing an acceptance test case for my changes, I have encountered one issue. The issue was my test case was running perfectly fine when it was ran alone but it get’s failed when it runs after a one particular test case.

I have debugged further to know why this issue was raising. After debugging, I came to know the observers are getting broken when first test case ran and it affects my test case (as I have written test cases based on observer changes)

This is how the test case file looks:

    module() {
      test('acceptance 1', function() {
       ...logic
      }
      
      test('acceptance 2', function() {
       ...logic
      }
    }

In ember, we knew that when any property changes both beginPropertyChanges and endPropertyChanges function will be called. In beginPropertyChanges they’ll increment the deferred property(initially it’ll be zero) and in endPropertyChanges they’ll decrement the Property. I’m attaching the code for both beginPropertyChanges and endPropertyChanges.

  function beginPropertyChanges() {
    deferred++;
    suspendedObserverDeactivation();
  }

  function endPropertyChanges() {
    deferred--;
    if (deferred <= 0) {
      flushSyncObservers();
      resumeObserverDeactivation();
    }
  }

What happens for my case is that, when first test case was run it incremented the deferred property from zero to one and due to some mistake made in first test case the endPropertyChanges haven’t called. So due to this when my test case was run, again the beginPropertyChanges function get’s called deferred property will be incremented (from 1 to 2) and in endPropertyChanges it’ll be decremented (from 2 to 1) so it’ll never be zero or less then zero. Hence both flushSyncObservers and resumeObserverDeactivation will not be called and ends making my test case fail due to observers brokerage.

How I can make the deferred property as zero, So that my test case will not get fail?

0

There are 0 best solutions below