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

QUnit integration test hangs during route transition #35

Closed
samheuck opened this issue Nov 20, 2013 · 11 comments
Closed

QUnit integration test hangs during route transition #35

samheuck opened this issue Nov 20, 2013 · 11 comments

Comments

@samheuck
Copy link

ember-simple-auth config:

App.initializer({

  initialize: function(container, application) {
    Ember.SimpleAuth.setup(container, application, {
      loginRoute: 'user.login',
      routeAfterLogin: '/user/dashboard',
      routeAfterLogout: '/user/login',
      serverTokenEndpoint: '/api/token',
    });
  }
});

The Test:

test("Visit login page", function() {
  expect(1);
  visit("/user/login");
  andThen(function() {
    ok(true);
   });
});

The problem:

The test hangs during the route transition.

DEBUG: 'DEBUG: -------------------------------'
DEBUG: 'DEBUG: Ember      : 1.2.0-beta.3'
DEBUG: 'DEBUG: Ember Data : 1.0.0-beta.2'
DEBUG: 'DEBUG: Handlebars : 1.1.2'
DEBUG: 'DEBUG: jQuery     : 1.9.1'
DEBUG: 'DEBUG: -------------------------------'
INFO: 'generated -> route:user', Object{fullName: 'route:user'}
INFO: 'Rendering application with default view <appkit@view:toplevel::ember296>', Object{fullName: 'view:application'}
INFO: 'generated -> controller:user', Object{fullName: 'controller:user'}
INFO: 'Rendering user with default view <appkit@view:default::ember317>', Object{fullName: 'view:user'}
INFO: 'Rendering user.login with default view <appkit@view:default::ember329>', Object{fullName: 'view:user.login'}
LOG: 'Transitioned into 'user.login''
INFO: 'generated -> route:user', Object{fullName: 'route:user'}
INFO: 'Rendering application with default view <appkit@view:toplevel::ember398>', Object{fullName: 'view:application'}
INFO: 'generated -> controller:user', Object{fullName: 'controller:user'}
INFO: 'Rendering user with default view <appkit@view:default::ember416>', Object{fullName: 'view:user'}
INFO: 'Rendering user.login with default view <appkit@view:default::ember422>', Object{fullName: 'view:user.login'}
LOG: 'Transitioned into 'user.login''
LOG: 'Transitioned into 'user.login''

Hangs right here

The test will finish if I override the init function in simple-auth and strip out the body of that function. I think maybe there is an async call in init that isn't resolving or something?

Other than this test failing, ember-simple-auth is working as expected. All protected routes require login and the session object is being returned correctly.

FYI this is within an ember app kit project.

@marcoow
Copy link
Member

marcoow commented Nov 21, 2013

It's a little hard to help without having access to the code. Accessing the login route shouldn't actually trigger anything in Ember.SimpleAuth though. Also I'm not sure which init function you're talking about.

As a side note (though I don't think that's causing your problem): routeAfterLogin and routeAfterLogout are supposed to be Ember route identifiers so you'd want to specify them as user.dashboard and user.login.

@matthooks
Copy link

I'm having the same issue and I've narrowed it down to a simple test case:

https://github.com/matthooks/ember-karma-simple-auth-issue

Run karma start. With the initializer, the application hangs when visit() is called. Without it, everything runs fine.

@matthooks
Copy link

@marcoow
Copy link
Member

marcoow commented Nov 25, 2013

I think the problem is the use of Ember.run.later somehow breaks testing. Probably best to disable it in testing mode...

@matthooks
Copy link

I'm still digging to figure out why that line is breaking things. The plugin seems to work fine without it. What's the intention of that run.later call?

@marcoow
Copy link
Member

marcoow commented Nov 26, 2013

The syncProperties method periodically re-reads the cookie to see changes in the stored values (e.g. for the case when you have 2 tabs open, logout in one and should be logged out in the 2nd one as well). I'll disable that in Ember testing mode, shouldn't have any effect on anything really...

@AlphaGit
Copy link

Since I arrived with this exact same problem, I believe I can provide more info for future visitors, even knowing that this issue has already been addressed.

Most of the actions that Ember.testing executes (like visit) will append to a promise that gets executed action after action in the right order. In order to pass to the next action, Ember.testing makes sure that there is nothing pending, so that the step can be considered complete and move forward.

Along with the things that are tested for, pending AJAX requests are verified, and also scheduled timers. These timers may arise from, you guessed it, Ember.run.later calls. If for any reason you would have in your code periodic Ember.run.later methods (so that one is always waiting to be excuted), it's likely that you'll face this issue.

I've faced it myself in a similar scenario: My server returns a OAuth access token with 100 hours until expired, so ember-simpleAuth registers a call close to the expiration time with Ember.run.later to refresh the token. This will, however, prevent the test from moving along. My specific situations has been fixed in further versions but any similar behavior will reproduce the issue (which is likely a conclusion of the current design of Ember.testing).

Hope this helps to anyone with this issue, and sorry for the wall of text.

@fibigerg
Copy link

Hello and thank you. This problem has not been fixed, yet.

@marcoow
Copy link
Member

marcoow commented May 29, 2014

@AlphaGit thanks for the great write up. Unfortunately just recognized it today. Should we disable automatic token refreshing in testing mode?

@AlphaGit
Copy link

@marcoow I think that's a fair approach. I don't think anyone would be relying on that feature for test scenarios.

@fibigerg
Copy link

@AlphaGit +1 I have just hotfixed it by commenting the line while testing :)

marcoow pushed a commit that referenced this issue Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants