|
@@ -519,7 +519,7 @@ describe('back_fill_file_hash script', function () {
|
|
|
/**
|
|
/**
|
|
|
* @param {Array<string>} args
|
|
* @param {Array<string>} args
|
|
|
* @param {boolean} shouldHaveWritten
|
|
* @param {boolean} shouldHaveWritten
|
|
|
- * @return {Promise<{result, stats: any}>}
|
|
|
|
|
|
|
+ * @return {Promise<{result, stats: any, migrationCreated: boolean}>}
|
|
|
*/
|
|
*/
|
|
|
async function tryRunScript(args = [], shouldHaveWritten) {
|
|
async function tryRunScript(args = [], shouldHaveWritten) {
|
|
|
const result = await rawRunScript([
|
|
const result = await rawRunScript([
|
|
@@ -553,7 +553,10 @@ describe('back_fill_file_hash script', function () {
|
|
|
'should not have any remaining deferred batches'
|
|
'should not have any remaining deferred batches'
|
|
|
)
|
|
)
|
|
|
delete stats.deferredBatches
|
|
delete stats.deferredBatches
|
|
|
- return { stats, result }
|
|
|
|
|
|
|
+ const migrationCreated = !!(await db
|
|
|
|
|
+ .collection('migrations')
|
|
|
|
|
+ .findOne({ name: '20250519101128_binary_files_migration' }))
|
|
|
|
|
+ return { stats, result, migrationCreated }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -562,12 +565,15 @@ describe('back_fill_file_hash script', function () {
|
|
|
* @return {Promise<{result, stats: any}>}
|
|
* @return {Promise<{result, stats: any}>}
|
|
|
*/
|
|
*/
|
|
|
async function runScript(args = [], shouldHaveWritten = true) {
|
|
async function runScript(args = [], shouldHaveWritten = true) {
|
|
|
- const { stats, result } = await tryRunScript(args, shouldHaveWritten)
|
|
|
|
|
|
|
+ const { stats, result, migrationCreated } = await tryRunScript(
|
|
|
|
|
+ args,
|
|
|
|
|
+ shouldHaveWritten
|
|
|
|
|
+ )
|
|
|
if (result.status !== 0) {
|
|
if (result.status !== 0) {
|
|
|
console.log(result)
|
|
console.log(result)
|
|
|
expect(result).to.have.property('status', 0)
|
|
expect(result).to.have.property('status', 0)
|
|
|
}
|
|
}
|
|
|
- return { stats, result }
|
|
|
|
|
|
|
+ return { stats, result, migrationCreated }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -813,21 +819,7 @@ describe('back_fill_file_hash script', function () {
|
|
|
!processHashedFiles ? ['--skip-hashed-files'] : [],
|
|
!processHashedFiles ? ['--skip-hashed-files'] : [],
|
|
|
false
|
|
false
|
|
|
)
|
|
)
|
|
|
- let stats = {
|
|
|
|
|
- ...STATS_ALL_ZERO,
|
|
|
|
|
- // We still need to iterate over all the projects and blobs.
|
|
|
|
|
- projects: 10,
|
|
|
|
|
- blobs: 10,
|
|
|
|
|
-
|
|
|
|
|
- badFileTrees: 4,
|
|
|
|
|
- }
|
|
|
|
|
- if (processHashedFiles) {
|
|
|
|
|
- stats = sumStats(stats, {
|
|
|
|
|
- ...STATS_ALL_ZERO,
|
|
|
|
|
- blobs: 2,
|
|
|
|
|
- })
|
|
|
|
|
- }
|
|
|
|
|
- expect(rerun.stats).deep.equal(stats)
|
|
|
|
|
|
|
+ expect(rerun.stats).deep.equal(statsForRerun(processHashedFiles))
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -929,6 +921,24 @@ describe('back_fill_file_hash script', function () {
|
|
|
STATS_UP_FROM_PROJECT1_ONWARD
|
|
STATS_UP_FROM_PROJECT1_ONWARD
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ function statsForRerun(processHashedFiles = true) {
|
|
|
|
|
+ let stats = {
|
|
|
|
|
+ ...STATS_ALL_ZERO,
|
|
|
|
|
+ // We still need to iterate over all the projects and blobs.
|
|
|
|
|
+ projects: 10,
|
|
|
|
|
+ blobs: 10,
|
|
|
|
|
+
|
|
|
|
|
+ badFileTrees: 4,
|
|
|
|
|
+ }
|
|
|
|
|
+ if (processHashedFiles) {
|
|
|
|
|
+ stats = sumStats(stats, {
|
|
|
|
|
+ ...STATS_ALL_ZERO,
|
|
|
|
|
+ blobs: 2,
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ return stats
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
describe('error cases', function () {
|
|
describe('error cases', function () {
|
|
|
beforeEach('prepare environment', prepareEnvironment)
|
|
beforeEach('prepare environment', prepareEnvironment)
|
|
|
|
|
|
|
@@ -957,6 +967,9 @@ describe('back_fill_file_hash script', function () {
|
|
|
'failed to process file, trying again'
|
|
'failed to process file, trying again'
|
|
|
)
|
|
)
|
|
|
expect(t1 - t0).to.be.below(10_000)
|
|
expect(t1 - t0).to.be.below(10_000)
|
|
|
|
|
+ expect(result.stderr).to.include(
|
|
|
|
|
+ 'The binary files migration failed, see above.'
|
|
|
|
|
+ )
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
it('should retry on error', async function () {
|
|
it('should retry on error', async function () {
|
|
@@ -1021,6 +1034,14 @@ describe('back_fill_file_hash script', function () {
|
|
|
it('should print stats', function () {
|
|
it('should print stats', function () {
|
|
|
expect(output.stats).deep.equal(STATS_ALL)
|
|
expect(output.stats).deep.equal(STATS_ALL)
|
|
|
})
|
|
})
|
|
|
|
|
+ it('should print a warning message', () => {
|
|
|
|
|
+ expect(output.result.stderr).to.include(
|
|
|
|
|
+ 'The binary files migration succeeded on a subset of files'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ it('should not create the migration', () => {
|
|
|
|
|
+ expect(output.migrationCreated).to.equal(false)
|
|
|
|
|
+ })
|
|
|
it('should have logged the bad file-tree', function () {
|
|
it('should have logged the bad file-tree', function () {
|
|
|
expectBadFileTreeMessage(
|
|
expectBadFileTreeMessage(
|
|
|
projectIdBadFileTree0,
|
|
projectIdBadFileTree0,
|
|
@@ -1081,6 +1102,14 @@ describe('back_fill_file_hash script', function () {
|
|
|
badFileTrees: 4,
|
|
badFileTrees: 4,
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|
|
|
|
|
+ it('should print a success message', () => {
|
|
|
|
|
+ expect(output2.result.stderr).to.include(
|
|
|
|
|
+ 'The binary files migration succeeded.'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ it('should create the migration', () => {
|
|
|
|
|
+ expect(output2.migrationCreated).to.equal(true)
|
|
|
|
|
+ })
|
|
|
commonAssertions(true)
|
|
commonAssertions(true)
|
|
|
})
|
|
})
|
|
|
describe('report mode', function () {
|
|
describe('report mode', function () {
|
|
@@ -1260,7 +1289,30 @@ Sampled stats for deleted projects:
|
|
|
it('should print stats for part 1', function () {
|
|
it('should print stats for part 1', function () {
|
|
|
expect(outputPart1.stats).to.deep.equal(STATS_UP_FROM_PROJECT1_ONWARD)
|
|
expect(outputPart1.stats).to.deep.equal(STATS_UP_FROM_PROJECT1_ONWARD)
|
|
|
})
|
|
})
|
|
|
|
|
+ it('should warn about split run', () => {
|
|
|
|
|
+ expect(outputPart0.result.stderr).to.include(
|
|
|
|
|
+ 'The binary files migration succeeded on a subset of files'
|
|
|
|
|
+ )
|
|
|
|
|
+ expect(outputPart1.result.stderr).to.include(
|
|
|
|
|
+ 'The binary files migration succeeded on a subset of files'
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
commonAssertions()
|
|
commonAssertions()
|
|
|
|
|
+
|
|
|
|
|
+ describe('with a full run afterwards', () => {
|
|
|
|
|
+ let output
|
|
|
|
|
+ before('run script', async function () {
|
|
|
|
|
+ output = await runScript([])
|
|
|
|
|
+ })
|
|
|
|
|
+ it('should print stats', function () {
|
|
|
|
|
+ expect(output.stats).to.deep.equal(
|
|
|
|
|
+ sumStats(statsForRerun(false), STATS_FILES_HASHED_EXTRA)
|
|
|
|
|
+ )
|
|
|
|
|
+ })
|
|
|
|
|
+ it('should create the migration', () => {
|
|
|
|
|
+ expect(output.migrationCreated).to.equal(true)
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
describe('projectIds from file', function () {
|
|
describe('projectIds from file', function () {
|
|
@@ -1337,6 +1389,10 @@ Sampled stats for deleted projects:
|
|
|
expect(outputPart0.stats).to.deep.equal(STATS_UP_TO_PROJECT1)
|
|
expect(outputPart0.stats).to.deep.equal(STATS_UP_TO_PROJECT1)
|
|
|
expect(outputPart1.stats).to.deep.equal(STATS_UP_FROM_PROJECT1_ONWARD)
|
|
expect(outputPart1.stats).to.deep.equal(STATS_UP_FROM_PROJECT1_ONWARD)
|
|
|
})
|
|
})
|
|
|
|
|
+ it('should not create the migration ', () => {
|
|
|
|
|
+ expect(outputPart0.migrationCreated).to.equal(false)
|
|
|
|
|
+ expect(outputPart1.migrationCreated).to.equal(false)
|
|
|
|
|
+ })
|
|
|
commonAssertions()
|
|
commonAssertions()
|
|
|
})
|
|
})
|
|
|
})
|
|
})
|