-
Notifications
You must be signed in to change notification settings - Fork 9
feat(mongodb-downloader)!: use a lockfile to prevent redundant parallel downloads MONGOSH-1875 #580
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
20e4664
chore(mongodb-downloader): use a lockfile to prevent redundant parall…
gagik 1ef4dc5
chore: cleanup, use proper-lockfile, use original interface
gagik 8bab148
chore: use class
gagik 9f50210
chore: add proper tests
gagik fb9f1c7
chore: version naming tests
gagik e14716a
chore: rename file
gagik 365a452
docs: add migration guide
gagik 6e0975e
chore: correct docs
gagik 7078c3f
chore: fix package.json
gagik cc899eb
Merge branch 'main' of github.com:mongodb-js/devtools-shared into gag…
gagik ea6d5c0
chore: update mongodb-runner
gagik 6e82751
chore: fixup naming logic
gagik b538f66
Merge branch 'main' of github.com:mongodb-js/devtools-shared into gag…
gagik 10afb7c
chore: update readme
gagik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
packages/mongodb-downloader/src/download-integration.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| import { expect } from 'chai'; | ||
| import { promises as fs } from 'fs'; | ||
| import path from 'path'; | ||
| import os from 'os'; | ||
| import { MongoDbDownloader } from './index'; | ||
|
|
||
| describe('downloader with Locking', function () { | ||
| this.timeout(60000); | ||
|
|
||
| let tmpDir: string; | ||
|
|
||
| beforeEach(async function () { | ||
| tmpDir = path.join(os.tmpdir(), `download-integration-tests-${Date.now()}`); | ||
| await fs.mkdir(tmpDir, { recursive: true }); | ||
| }); | ||
| const version = '8.2.0'; | ||
|
|
||
| afterEach(async function () { | ||
| try { | ||
| await fs.rm(tmpDir, { recursive: true }); | ||
| } catch { | ||
| // Ignore cleanup errors | ||
| } | ||
| }); | ||
|
|
||
| it('should prevent concurrent downloads of the same version', async function () { | ||
| const downloader = new MongoDbDownloader({ tmpdir: tmpDir }); | ||
|
|
||
| const results = await Promise.all([ | ||
| downloader.downloadMongoDbWithVersionInfo(version), | ||
| downloader.downloadMongoDbWithVersionInfo(version), | ||
| downloader.downloadMongoDbWithVersionInfo(version), | ||
| ]); | ||
|
|
||
| // All results should be identical | ||
| expect(results[0].version).to.equal(version); | ||
| expect(results[1].version).to.equal(version); | ||
| expect(results[2].version).to.equal(version); | ||
|
|
||
| expect(results[0].downloadedBinDir).to.equal(results[1].downloadedBinDir); | ||
| expect(results[1].downloadedBinDir).to.equal(results[2].downloadedBinDir); | ||
|
|
||
| // Verify the downloaded directory exists and contains mongod | ||
| expect(await fs.stat(results[0].downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(results[0].downloadedBinDir, 'mongod'))).to | ||
| .be.ok; | ||
| }); | ||
|
|
||
| it('should wait for existing download to complete', async function () { | ||
| // First, download MongoDB normally | ||
| const downloader = new MongoDbDownloader({ tmpdir: tmpDir }); | ||
| const result = await downloader.downloadMongoDbWithVersionInfo(version); | ||
|
|
||
| expect(result.version).to.equal(version); | ||
| expect(result.downloadedBinDir).to.be.a('string'); | ||
|
|
||
| // Verify the downloaded directory exists and contains mongod | ||
| expect(await fs.stat(result.downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(result.downloadedBinDir, 'mongod'))).to.be | ||
| .ok; | ||
| }); | ||
|
|
||
| it('should skip download if already completed', async function () { | ||
| // First download | ||
| const downloader = new MongoDbDownloader({ tmpdir: tmpDir }); | ||
| const result1 = await downloader.downloadMongoDbWithVersionInfo(version); | ||
|
|
||
| // Second download should use cached result | ||
| const result2 = await downloader.downloadMongoDbWithVersionInfo(version); | ||
|
|
||
| expect(result1.version).to.equal(version); | ||
| expect(result2.version).to.equal(version); | ||
| expect(result1.downloadedBinDir).to.equal(result2.downloadedBinDir); | ||
|
|
||
| // Verify the downloaded directory exists and contains mongod | ||
| expect(await fs.stat(result1.downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(result1.downloadedBinDir, 'mongod'))).to.be | ||
| .ok; | ||
| }); | ||
|
|
||
| it('should handle different versions independently', async function () { | ||
| const version2 = '8.1.0'; | ||
|
|
||
| // Download different versions | ||
| const downloader = new MongoDbDownloader({ tmpdir: tmpDir }); | ||
| const [result1, result2] = await Promise.all([ | ||
| downloader.downloadMongoDbWithVersionInfo(version), | ||
| downloader.downloadMongoDbWithVersionInfo(version2), | ||
| ]); | ||
|
|
||
| expect(result1.version).to.equal(version); | ||
| expect(result2.version).to.equal(version2); | ||
| expect(result1.downloadedBinDir).to.not.equal(result2.downloadedBinDir); | ||
|
|
||
| // Verify both downloaded directories exist and contain mongod | ||
| expect(await fs.stat(result1.downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(result1.downloadedBinDir, 'mongod'))).to.be | ||
| .ok; | ||
| expect(await fs.stat(result2.downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(result2.downloadedBinDir, 'mongod'))).to.be | ||
| .ok; | ||
| }); | ||
|
|
||
| it('should handle promise caching correctly', async function () { | ||
| const version = '8.2.0'; | ||
|
|
||
| // Start multiple downloads in sequence (not parallel) | ||
| const downloader = new MongoDbDownloader({ tmpdir: tmpDir }); | ||
| const result1 = await downloader.downloadMongoDbWithVersionInfo(version); | ||
| const result2 = await downloader.downloadMongoDbWithVersionInfo(version); | ||
| const result3 = await downloader.downloadMongoDbWithVersionInfo(version); | ||
|
|
||
| // All should return the same result | ||
| expect(result1.version).to.equal(version); | ||
| expect(result2.version).to.equal(version); | ||
| expect(result3.version).to.equal(version); | ||
|
|
||
| expect(result1.downloadedBinDir).to.equal(result2.downloadedBinDir); | ||
| expect(result2.downloadedBinDir).to.equal(result3.downloadedBinDir); | ||
|
|
||
| // Verify the downloaded directory exists and contains mongod | ||
| expect(await fs.stat(result1.downloadedBinDir)).to.be.ok; | ||
| expect(await fs.stat(path.join(result1.downloadedBinDir, 'mongod'))).to.be | ||
| .ok; | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.