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

UI: XHR keys need to include the method as well #4319

Merged
merged 3 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions ui/app/adapters/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ export default Watchable.extend({
},

xhrKey(url, method, options = {}) {
const plainKey = this._super(...arguments);
const namespace = options.data && options.data.namespace;
if (namespace) {
return `${url}?namespace=${namespace}`;
return `${plainKey}?namespace=${namespace}`;
}
return url;
return plainKey;
},

relationshipFallbackLinks: {
Expand Down
10 changes: 5 additions & 5 deletions ui/app/adapters/watchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export default ApplicationAdapter.extend({
return ajaxOptions;
},

xhrKey(url /* method, options */) {
return url;
xhrKey(url, method /* options */) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice that these were already being passed 👌

return `${method} ${url}`;
},

findAll(store, type, sinceToken, snapshotRecordArray, additionalParams = {}) {
Expand Down Expand Up @@ -149,7 +149,7 @@ export default ApplicationAdapter.extend({
return;
}
const url = this.urlForFindRecord(id, modelName);
this.get('xhrs').cancel(url);
this.get('xhrs').cancel(`GET ${url}`);
},

cancelFindAll(modelName) {
Expand All @@ -161,7 +161,7 @@ export default ApplicationAdapter.extend({
if (params) {
url = `${url}?${params}`;
}
this.get('xhrs').cancel(url);
this.get('xhrs').cancel(`GET ${url}`);
},

cancelReloadRelationship(model, relationshipName) {
Expand All @@ -175,7 +175,7 @@ export default ApplicationAdapter.extend({
);
} else {
const url = model[relationship.kind](relationship.key).link();
this.get('xhrs').cancel(url);
this.get('xhrs').cancel(`GET ${url}`);
}
},
});
37 changes: 36 additions & 1 deletion ui/tests/unit/adapters/job-test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import EmberObject from '@ember/object';
import { run } from '@ember/runloop';
import { assign } from '@ember/polyfills';
import { test } from 'ember-qunit';
Expand All @@ -10,8 +11,12 @@ moduleForAdapter('job', 'Unit | Adapter | Job', {
'adapter:job',
'service:token',
'service:system',
'model:namespace',
'model:allocation',
'model:deployment',
'model:evaluation',
'model:job-summary',
'model:job-version',
'model:namespace',
'adapter:application',
'service:watchList',
],
Expand Down Expand Up @@ -292,6 +297,36 @@ test('requests can be canceled even if multiple requests for the same URL were m
});
});

test('canceling a find record request will never cancel a request with the same url but different method', function(assert) {
const { pretender } = this.server;
const jobId = JSON.stringify(['job-1', 'default']);

pretender.get('/v1/job/:id', () => [200, {}, '{}'], true);
pretender.delete('/v1/job/:id', () => [204, {}, ''], 200);

this.subject().findRecord(null, { modelName: 'job' }, jobId, {
reload: true,
adapterOptions: { watch: true },
});

this.subject().stop(EmberObject.create({ id: jobId }));

const { request: getXHR } = pretender.requestReferences[0];
const { request: deleteXHR } = pretender.requestReferences[1];
assert.equal(getXHR.status, 0, 'Get request is still pending');
assert.equal(deleteXHR.status, 0, 'Delete request is still pending');

// Schedule the cancelation before waiting
run.next(() => {
this.subject().cancelFindRecord('job', jobId);
});

return wait().then(() => {
assert.ok(getXHR.aborted, 'Get request was aborted');
assert.notOk(deleteXHR.aborted, 'Delete request was aborted');
});
});

function makeMockModel(id, options) {
return assign(
{
Expand Down