Skip to content
This repository has been archived by the owner on Jun 2, 2024. It is now read-only.

Commit

Permalink
fix: should update etag after abbreviated meta change (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 authored Oct 1, 2021
1 parent ee6ba63 commit 62fdbd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions controllers/registry/package/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,10 @@ function* handleAbbreviatedMetaRequest(ctx, name, modifiedTime, tags, rows, cach
if ((!distTags.latest && !latestMod) || distTags.latest === pkg.version) {
latestMod = row;
}
// abbreviatedMeta row maybe update by syncer on missing attributes add
if (!modifiedTime || row.gmt_modified > modifiedTime) {
modifiedTime = row.gmt_modified;
}
}

if (!latestMod) {
Expand Down
13 changes: 12 additions & 1 deletion test/controllers/sync_module_worker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,14 @@ describe('test/controllers/sync_module_worker.test.js', () => {
let pkg;
let pkgV2;
let pkgV3;
let lastResHeaders;
function checkResult() {
return function (done) {
request(app)
.get('/mk2test-module-cnpmsync')
.set('accept', 'application/vnd.npm.install-v1+json')
.expect(function (res) {
// console.log(JSON.stringify(res.body, null, 2));
lastResHeaders = res.headers;
pkg = res.body.versions['1.0.0'];
assert(pkg.os[0] === 'linux');
assert(pkg.cpu[0] === 'x64');
Expand All @@ -191,6 +192,10 @@ describe('test/controllers/sync_module_worker.test.js', () => {
};
}
yield checkResult();
const oldEtag = lastResHeaders.etag;
// check etag keep same again
yield checkResult();
assert(oldEtag == lastResHeaders.etag);

// modify result
yield packageService.updateModuleAbbreviatedPackage({
Expand Down Expand Up @@ -244,6 +249,12 @@ describe('test/controllers/sync_module_worker.test.js', () => {

// check again still work
yield checkResult();
const newEtag = lastResHeaders.etag;
assert(newEtag !== oldEtag);

// check etag keep same again
yield checkResult();
assert(newEtag == lastResHeaders.etag);
});

it('should sync upstream first', function* () {
Expand Down

0 comments on commit 62fdbd4

Please sign in to comment.