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

Clear cached time when setting expiration to null #1463

Merged
merged 7 commits into from
Dec 8, 2017

Conversation

stevenwu
Copy link
Collaborator

@marcoow the issue is that calculateExpirationTime always uses the cached expiration time if there is one.

I've decided to clear the cache when user nulls expiration time, however we get Error: Assertion Failed: Attempting to lookup an injected property on an object without a container, ensure that the object was instantiated via a container.. Thoughts?

#854

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; I guess the error is most likely caused by something in the tests not being set up correctly (as the property function now needs the cookies service while it previously didn't).

if (value < 90) {
// When nulling expiry time on purpose, we need to clear the cached value.
// Otherwise, `_calculateExpirationTime` will reuse it.
if (this.get('_cookies') && value === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for this.get('_cookies') should not actually be necessary.

this.get('_cookies').clear(`${this.get('cookieName')}-expiration_time`);
}

if (value < 90 && value !== null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd make this an else if for clarity.

@stevenwu
Copy link
Collaborator Author

The cookie service is called during init

https://github.com/stevenwu/ember-simple-auth/blob/f8f3a11b5345cc4a9ea21ff544316c9d4f90faef/addon/session-stores/cookie.js#L162-L165

so we need to set the container in tests before that. How do we do that?

@marcoow
Copy link
Member

marcoow commented Oct 25, 2017

This creates a cookie store that has the _cookies service set during init. I think something like that should work?

@stevenwu stevenwu changed the title [wip] Clear cached time when setting expiration to null Clear cached time when setting expiration to null Oct 27, 2017
@stevenwu
Copy link
Collaborator Author

I'm unable to run fastboot tests locally, even on master.

  1) Graceful regression tests "before all" hook:
     the object {
  "code": 1
  "errors": [
    "Cannot find module 'ember-cli-preprocess-registry/preprocessors'\n"
    "Error: Cannot find module 'ember-cli-preprocess-registry/preprocessors'\n    at Function.Module._resolveFilename (module.js:536:15)\n    at Function.Module._load (module.js:466:25)\n    at Module.require (module.js:579:17)\n    at require (internal/module.js:11:18)\n    at Object.<anonymous> (/private/var/folders/jw/xxf7ygd91039vt0ysv21fsww0000gp/T/d-1171012-57398-3opn1v.hho57/pristine/node_modules/ember-cli-fastboot/index.js:18:11)\n    at Module._compile (module.js:635:30)\n    at Object.Module._extensions..js (module.js:646:10)\n    at Module.load (module.js:554:32)\n    at tryModuleLoad (module.js:497:12)\n    at Function.Module._load (module.js:489:3)\n"
  ]
  "output": []
  "signal": [null]
} was thrown, throw an Error :)
  Error: the object {
    "code": 1
    "errors": [
      "Cannot find module 'ember-cli-preprocess-registry/preprocessors'\n"
    ]
    "output": []
    "signal": [null]
  } was thrown, throw an Error :)
      at tryCatch (node_modules/rsvp/dist/rsvp.js:525:12)
      at invokeCallback (node_modules/rsvp/dist/rsvp.js:538:13)
      at publish (node_modules/rsvp/dist/rsvp.js:508:7)
      at publishRejection (node_modules/rsvp/dist/rsvp.js:443:3)
      at flush (node_modules/rsvp/dist/rsvp.js:2400:5)

  2) Integration tests "before all" hook:
     Error: Could not find fixtures directory. Make sure you have a fixtures directory in your `test/` directory. You may encounter this issue if you have npm linked this package; copy it to your node_modules directory instead.
      at findFixturesPath (node_modules/ember-cli-addon-tests/lib/utilities/copy-fixture-files.js:15:11)
      at copyFixtureFiles (node_modules/ember-cli-addon-tests/lib/utilities/copy-fixture-files.js:23:20)
      at node_modules/ember-cli-addon-tests/lib/models/addon-test-app.js:30:9
      at tryCatch (node_modules/rsvp/dist/rsvp.js:525:12)
      at invokeCallback (node_modules/rsvp/dist/rsvp.js:538:13)
      at publish (node_modules/rsvp/dist/rsvp.js:508:7)
      at flush (node_modules/rsvp/dist/rsvp.js:2400:5)
      at _combinedTickCallback (internal/process/next_tick.js:131:7)
      at process._tickCallback (internal/process/next_tick.js:180:9)

@marcoow
Copy link
Member

marcoow commented Nov 13, 2017

Yeah, I can reproduce the FastBoot tests error - I'll fix that.

@marcoow
Copy link
Member

marcoow commented Nov 13, 2017

Hm, I cannot reproduce this anymore now - both

git clean -dfx
yarn --pure-lockfile
npm run test:fastboot

as well as

git clean -dfx
yarn --no-lockfile
npm run test:fastboot

work for me. Can you check whether git clean -dfx does fix it for you @stevenwu?

@stevenwu
Copy link
Collaborator Author

I still have the error, even on a fresh clone. I'm on node 8.9.1 and npm 5.5.1.

@marcoow
Copy link
Member

marcoow commented Nov 13, 2017

Hm, that's very strange. What's your global ember-cli version?

@stevenwu
Copy link
Collaborator Author

2.16.2

@stevenwu
Copy link
Collaborator Author

stevenwu commented Nov 13, 2017

I get this though, if I run yarn --pure-lockfile and not yarn

~/temp/ember-simple-auth master
❯ ember --version
module.js:538
    throw err;
    ^

Error: Cannot find module 'broccoli-merge-trees'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/Users/steve/temp/ember-simple-auth/node_modules/ember-cli/lib/broccoli/merge-trees.js:2:28)
    at Module._compile (module.js:635:30)
    at Object.Module._extensions..js (module.js:646:10)
    at Module.load (module.js:554:32)
    at tryModuleLoad (module.js:497:12)
    at Function.Module._load (module.js:489:3)

Test results will be the same.

@marcoow
Copy link
Member

marcoow commented Nov 14, 2017

Did you clean your node_modules, dist and tmp folders (git clean -dfx will completely clean your repo).

@stevenwu
Copy link
Collaborator Author

I can run the tests with node 8 and npm 4, so I think there's an issue with npm 5.

@stevenwu stevenwu force-pushed the fix-cached-expiration branch from ba95782 to cb493e3 Compare November 15, 2017 18:28
@marcoow
Copy link
Member

marcoow commented Nov 15, 2017

Hm, ok - as that's almost certainly not an issue with ESA let's ignore it for now as you can run the tests now.

// When nulling expiry time on purpose, we need to clear the cached value.
// Otherwise, `_calculateExpirationTime` will reuse it.
if (value === null) {
this.get('_cookies').clear(`${this.get('cookieName')}-expiration_time`);
Copy link
Collaborator Author

@stevenwu stevenwu Nov 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marcoow I don't know why this is causing

  1) Graceful regression tests does not error when using the adaptive store:
     AssertionError: expected undefined to deeply equal [ Array(1) ]

which asserts

expect(response.headers['set-cookie']).to.deep.equal(['ember_simple_auth-session=%7B%22authenticated%22%3A%7B%7D%7D; path=/'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try reproducing this outside of the tests - run ember s and have a look at the response.

Copy link
Member

@marcoow marcoow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good - the failing FastBoot test seems strange though…

if (value < 90) {
// When nulling expiry time on purpose, we need to clear the cached value.
// Otherwise, `_calculateExpirationTime` will reuse it.
if (value === null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd use isNone here.

@marcoow
Copy link
Member

marcoow commented Nov 24, 2017

The failing FastBoot test is due to the store creation logic being pretty broken - in particular with the adaptive store that the graceful regression test uses. I tried to do a quick "fix" but that should all be properly refactored. I'll do that in a separate PR.

@@ -26,7 +25,7 @@ describe('AdaptiveStore', () => {
beforeEach(function() {
store = Adaptive.extend({
_createStore(storeType, options) {
return this._super(storeType, assign(options, { _isFastBoot: false }));
return LocalStorage.create({ _isFastBoot: false }, options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all very bad of course but will be fixed in #1490

@marcoow marcoow merged commit f867f24 into mainmatter:master Dec 8, 2017
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

Successfully merging this pull request may close these issues.

2 participants