Repository navigation
test: use the run token for metamorph in integration tests #1206
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -240,26 +240,59 @@ test('resurrect() restarts a finished run, which then succeeds again', async () | |||||||
| }); | ||||||||
|
|
||||||||
| test('metamorph() transforms a started run into another Actor, keeping the run id', async () => { | ||||||||
| const run = await client.actor(HELLO_WORLD_ACTOR).start(); | ||||||||
| const runClient = client.run(run.id); | ||||||||
| // Metamorphing the run from outside is not allowed, so we cheat a bit: the Actor stores its own run token in its key-value store, | ||||||||
| // and we construct a new client with this token, and test that. | ||||||||
| const actor = await client.actors().create({ | ||||||||
| name: getRandomResourceName('actor'), | ||||||||
| versions: [ | ||||||||
| { | ||||||||
| versionNumber: '0.0', | ||||||||
| sourceType: ActorSourceType.SourceFiles, | ||||||||
| buildTag: 'latest', | ||||||||
| sourceFiles: [ | ||||||||
| { | ||||||||
| name: 'Dockerfile', | ||||||||
| format: 'TEXT', | ||||||||
| content: 'FROM apify/actor-node:22\nCOPY . ./\nCMD ["node", "main.js"]\n', | ||||||||
| }, | ||||||||
| { | ||||||||
| name: 'main.js', | ||||||||
| format: 'TEXT', | ||||||||
| content: ` | ||||||||
| const { Actor } = require('apify'); | ||||||||
| Actor.main(async () => { | ||||||||
| await Actor.setValue('TOKEN', process.env.APIFY_TOKEN, { contentType: 'text/plain' }); | ||||||||
| await new Promise((resolve) => setTimeout(resolve, 60000)); | ||||||||
| }); | ||||||||
| `, | ||||||||
| }, | ||||||||
| ], | ||||||||
| }, | ||||||||
| ], | ||||||||
| }); | ||||||||
| const actorClient = client.actor(actor.id); | ||||||||
| let runClient: RunClient | undefined; | ||||||||
|
|
||||||||
| try { | ||||||||
| await waitUntilStarted(runClient); | ||||||||
|
|
||||||||
| try { | ||||||||
| const metamorphedRun = await runClient.metamorph(HELLO_WORLD_ACTOR, { | ||||||||
| message: 'Hello from metamorph!', | ||||||||
| }); | ||||||||
| expect(metamorphedRun.id).toBe(run.id); | ||||||||
| await client.build((await actorClient.build('0.0')).id).waitForFinish(); | ||||||||
|
Contributor
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. we should check the build status, same as in Python Suggestion: check the build status, as the
Suggested change
✍️ Drafted by Claude Code |
||||||||
| const run = await actorClient.start(); | ||||||||
|
Contributor
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. shouldn't we add some limits to this run? Suggestion: this run sleeps for 60 s with the default memory, on an account that parallel tests share. Limits like the other custom Actor test in this file would keep it small and stop it if the cleanup fails:
Suggested change
✍️ Drafted by Claude Code |
||||||||
| runClient = client.run(run.id); | ||||||||
|
|
||||||||
| // Only the run's own API token may metamorph it, so take it from the Actor's key-value store. | ||||||||
| const record = await pollUntilCondition( | ||||||||
| async () => client.keyValueStore(run.defaultKeyValueStoreId).getRecord('TOKEN'), | ||||||||
| (rec) => rec !== undefined, | ||||||||
| { timeoutSecs: 120, backoffFactor: 2 }, | ||||||||
| ); | ||||||||
| const runTokenClient = makeClient(record!.value as string); | ||||||||
|
Contributor
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. provide a clear failure when the token is missing Suggestion:
Suggested change
✍️ Drafted by Claude Code |
||||||||
|
|
||||||||
| await runClient.waitForFinish(); | ||||||||
| } catch (err) { | ||||||||
| // hello-world can finish before the metamorph lands; the API call was still exercised. | ||||||||
| rethrowUnlessAlreadyFinished(err); | ||||||||
| } | ||||||||
| const metamorphedRun = await runTokenClient.run(run.id).metamorph(HELLO_WORLD_ACTOR); | ||||||||
|
Contributor
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. keep test coverage of the metamorph input body Nit: the old test sent an input to
Suggested change
✍️ Drafted by Claude Code |
||||||||
| expect(metamorphedRun.id).toBe(run.id); | ||||||||
| } finally { | ||||||||
| await runClient.waitForFinish(); | ||||||||
| await runClient.delete(); | ||||||||
| await runClient?.abort(); | ||||||||
| await runClient?.waitForFinish(); | ||||||||
| await runClient?.delete(); | ||||||||
| await actorClient.delete(); | ||||||||
| } | ||||||||
| }); | ||||||||
|
|
||||||||
|
|
||||||||
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.
Nit: this comment and the one at line 281 say the same thing, and the first line is longer than 120 chars. One comment here is enough, and line 281 can go:
✍️ Drafted by Claude Code