-
Notifications
You must be signed in to change notification settings - Fork 1
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
rename MapeoManager.start() and MapeoManager.stop() methods #399
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
// @ts-check | ||
import { test } from 'brittle' | ||
import { randomBytes } from 'crypto' | ||
import { join } from 'path' | ||
|
@@ -19,6 +20,66 @@ const projectMigrationsFolder = new URL('../drizzle/project', import.meta.url) | |
const clientMigrationsFolder = new URL('../drizzle/client', import.meta.url) | ||
.pathname | ||
|
||
test('start/stop lifecycle', async (t) => { | ||
const manager = new MapeoManager({ | ||
rootKey: KeyManager.generateRootKey(), | ||
projectMigrationsFolder, | ||
clientMigrationsFolder, | ||
dbFolder: ':memory:', | ||
coreStorage: () => new RAM(), | ||
}) | ||
|
||
const project = await manager.getProject(await manager.createProject()) | ||
|
||
await manager.startMediaServer() | ||
|
||
const blobUrl1 = await project.$blobs.getUrl({ | ||
driveId: randomBytes(32).toString('hex'), | ||
name: randomBytes(8).toString('hex'), | ||
type: 'photo', | ||
variant: 'original', | ||
}) | ||
const response1 = await fetch(blobUrl1) | ||
t.is(response1.status, 404, 'server started and listening') | ||
|
||
await manager.startMediaServer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. get a url, check the port hasn't changed |
||
|
||
const blobUrl2 = await project.$blobs.getUrl({ | ||
driveId: randomBytes(32).toString('hex'), | ||
name: randomBytes(8).toString('hex'), | ||
type: 'video', | ||
variant: 'original', | ||
}) | ||
t.is( | ||
new URL(blobUrl1).port, | ||
new URL(blobUrl2).port, | ||
'server port is the same' | ||
) | ||
|
||
await manager.stopMediaServer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. check the url previously returned no longer works (should return a connection error) |
||
|
||
await t.exception.all(async () => { | ||
await fetch(blobUrl2) | ||
}, 'failed to fetch due to connection error') | ||
|
||
await manager.startMediaServer() | ||
|
||
const blobUrl3 = await project.$blobs.getUrl({ | ||
driveId: randomBytes(32).toString('hex'), | ||
name: randomBytes(8).toString('hex'), | ||
type: 'audio', | ||
variant: 'original', | ||
}) | ||
const response3 = await fetch(blobUrl3) | ||
t.is(response3.status, 404, 'server started and listening') | ||
|
||
await manager.stopMediaServer() | ||
|
||
await t.exception.all(async () => { | ||
await fetch(blobUrl3) | ||
}, 'failed to fetch due to connection error') | ||
}) | ||
|
||
test('retrieving blobs using url', async (t) => { | ||
const clock = FakeTimers.install({ shouldAdvanceTime: true }) | ||
t.teardown(() => clock.uninstall()) | ||
|
@@ -40,12 +101,12 @@ test('retrieving blobs using url', async (t) => { | |
type: 'photo', | ||
variant: 'original', | ||
}) | ||
}, 'getting blob url fails if manager.start() has not been called yet') | ||
}, 'getting blob url fails if manager.startMediaServer() has not been called yet') | ||
|
||
clock.tick(100_000) | ||
await exceptionPromise1 | ||
|
||
await manager.start() | ||
await manager.startMediaServer() | ||
|
||
await t.test('blob does not exist', async (st) => { | ||
const blobUrl = await project.$blobs.getUrl({ | ||
|
@@ -96,7 +157,7 @@ test('retrieving blobs using url', async (t) => { | |
st.alike(body, expected, 'matching reponse body') | ||
}) | ||
|
||
await manager.stop() | ||
await manager.stopMediaServer() | ||
|
||
const exceptionPromise2 = t.exception(async () => { | ||
await project.$blobs.getUrl({ | ||
|
@@ -130,12 +191,12 @@ test('retrieving icons using url', async (t) => { | |
pixelDensity: 1, | ||
size: 'small', | ||
}) | ||
}, 'getting icon url fails if manager.start() has not been called yet') | ||
}, 'getting icon url fails if manager.startMediaServer() has not been called yet') | ||
|
||
clock.tick(100_000) | ||
await exceptionPromise1 | ||
|
||
await manager.start() | ||
await manager.startMediaServer() | ||
|
||
await t.test('icon does not exist', async (st) => { | ||
const nonExistentIconId = randomBytes(32).toString('hex') | ||
|
@@ -194,7 +255,7 @@ test('retrieving icons using url', async (t) => { | |
st.alike(body, iconBuffer, 'matching response body') | ||
}) | ||
|
||
await manager.stop() | ||
await manager.stopMediaServer() | ||
|
||
const exceptionPromise2 = t.exception(async () => { | ||
await project.$icons.getIconUrl(randomBytes(32).toString('hex'), { | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check it's started: get a url, check it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to put data there, just returning 404 is enough to know it's started.