Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage of initializer causes race condition in tests. #22

Open
rwjblue opened this issue Jan 3, 2018 · 2 comments
Open

Usage of initializer causes race condition in tests. #22

rwjblue opened this issue Jan 3, 2018 · 2 comments
Labels

Comments

@rwjblue
Copy link
Collaborator

rwjblue commented Jan 3, 2018

Since initializers are not ran for moduleFor and moduleForComponent tests, those tests will be using the non-Ember specific spaniel engine (which is not run-loop aware). The first time that a spaniel call is made the spaniel internal variable globalEngine is setup (defaulting to the "normal" spaniel engine) and cannot be reset.

As you can see here:

let globalEngine: EngineInterface = null;

export function setGlobalEngine(engine: EngineInterface): boolean {
  if (!!globalEngine) {
    return false;
  }
  globalEngine = engine;
  return true;
}

export function getGlobalEngine() {
  return globalEngine || (globalEngine = new Engine());
}

This means that in any circumstance where a moduleFor or moduleForComponent test is ran before a moduleForAcceptance (the only tests prior to emberjs/rfcs#232 and emberjs/rfcs#268 that actually run initializers) the entire rest of the test run is going to run with the incorrect spaniel engine.


The fix is straightforward, this initializer should be removed:

https://github.com/asakusuma/ember-spaniel/blob/066cfdaf16ea3e939e1fdd440745c04ccdc4ea64/addon/initializers/spaniel.js#L4-L11

Instead, the custom spaniel engine should be moved to vendor/ and app.import'ed directly.

The app.imported code will always run (completely independent of the initialization process of an application), and everything will be 🌞 and 🌈 .

@asakusuma asakusuma added the bug label Jan 3, 2018
@asakusuma
Copy link
Collaborator

@lynchbomb does it make sense to fix this with the impending v3 spaniel release which removes setGlobalEngine?

@lynchbomb
Copy link
Collaborator

lynchbomb commented Jul 13, 2018

This is fixed once the Ember-Spaniel#v1.x and Spaniel#v4.x releases are rolled-out. setGlobalEngine is a thing of the past.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants