-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: proposal pre/post test steps #210
Merged
Merged
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
2660fec
hooks
usmanmani1122 8e3f3e4
Merge branch "usman/prepare-test-hook" into branch "usman/before-afte…
usmanmani1122 df80864
nit
usmanmani1122 0554920
fixes
usmanmani1122 5d4e465
Merge branch 'main' into usman/before-after-test-scripts
usmanmani1122 2c94fef
document prepare-test hook
usmanmani1122 a689ecc
address comments
usmanmani1122 61371f5
Merge branch 'main' into usman/before-after-test-scripts
usmanmani1122 9f24947
increase test timeout
usmanmani1122 3d6780c
increase test timeout 2.0
usmanmani1122 5b4c029
fix for spawn
usmanmani1122 608e2da
:)
usmanmani1122 0ee2a77
increase test timeout 3.0
usmanmani1122 7ad7d92
revert
usmanmani1122 f55ef1f
address comments
usmanmani1122 8b22861
Empty
usmanmani1122 b89fe4f
Empty
usmanmani1122 6d5c227
Empty
usmanmani1122 f121f67
Merge branch 'main' into usman/before-after-test-scripts
usmanmani1122 679a083
Address comments
usmanmani1122 f983826
lint
usmanmani1122 36a2a20
use tmp directory
usmanmani1122 5d54940
nit
usmanmani1122 ef3d10b
address comments + fix bug
usmanmani1122 963e59f
lint
usmanmani1122 1a137a4
nit
usmanmani1122 12c5042
nit
usmanmani1122 ac2c07b
Merge branch 'main' into usman/before-after-test-scripts
usmanmani1122 b34bdb6
Merge branch 'main' into usman/before-after-test-scripts
usmanmani1122 73a9c4b
add test + host folder notes
usmanmani1122 9d67bc1
lint
usmanmani1122 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
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,7 +1,29 @@ | ||||||
import { execSync } from 'node:child_process'; | ||||||
import { realpathSync } from 'node:fs'; | ||||||
import { spawnSync } from 'node:child_process'; | ||||||
import { existsSync, realpathSync } from 'node:fs'; | ||||||
import { resolve as resolvePath } from 'node:path'; | ||||||
import { fileSync as createTempFile } from 'tmp'; | ||||||
import { ProposalInfo, imageNameForProposal } from './proposals.js'; | ||||||
|
||||||
const createMessageFile = (proposal: ProposalInfo) => | ||||||
createTempFile({ prefix: proposal.proposalName }); | ||||||
|
||||||
const executeHostScriptIfPresent = ( | ||||||
extraEnv: typeof process.env, | ||||||
proposal: ProposalInfo, | ||||||
scriptName: string, | ||||||
) => { | ||||||
const scriptPath = `${resolvePath('.')}/proposals/${proposal.path}/host/${scriptName}`; | ||||||
if (existsSync(scriptPath)) { | ||||||
console.log( | ||||||
`Running script ${scriptName} for proposal ${proposal.proposalName}`, | ||||||
); | ||||||
spawnSync(scriptPath, { | ||||||
env: { ...process.env, ...extraEnv }, | ||||||
stdio: 'inherit', | ||||||
}); | ||||||
} | ||||||
}; | ||||||
|
||||||
/** | ||||||
* Used to propagate a SLOGFILE environment variable into Docker containers. | ||||||
* Any file identified by such a variable will be created if it does not already | ||||||
|
@@ -14,40 +36,101 @@ const propagateSlogfile = env => { | |||||
const { SLOGFILE } = env; | ||||||
if (!SLOGFILE) return []; | ||||||
|
||||||
execSync('touch "$SLOGFILE"'); | ||||||
return ['-e', 'SLOGFILE', '-v', `"$SLOGFILE:${realpathSync(SLOGFILE)}"`]; | ||||||
spawnSync('touch', [SLOGFILE]); | ||||||
|
||||||
return [ | ||||||
'--env', | ||||||
`SLOGFILE=${SLOGFILE}`, | ||||||
'--volume', | ||||||
`${SLOGFILE}:${realpathSync(SLOGFILE)}`, | ||||||
]; | ||||||
}; | ||||||
|
||||||
export const runTestImage = (proposal: ProposalInfo) => { | ||||||
console.log(`Running test image for proposal ${proposal.proposalName}`); | ||||||
const { name } = imageNameForProposal(proposal, 'test'); | ||||||
const slogOpts = propagateSlogfile(process.env); | ||||||
// 'rm' to remove the container when it exits | ||||||
const cmd = `docker run ${slogOpts.join(' ')} --rm ${name}`; | ||||||
execSync(cmd, { stdio: 'inherit' }); | ||||||
export const runTestImage = ({ | ||||||
extraDockerArgs = [], | ||||||
proposal, | ||||||
removeContainerOnExit = true, | ||||||
}: { | ||||||
extraDockerArgs?: Array<string>; | ||||||
proposal: ProposalInfo; | ||||||
removeContainerOnExit?: boolean; | ||||||
}) => { | ||||||
const { name: messageFilePath, removeCallback: removeTempFileCallback } = | ||||||
createMessageFile(proposal); | ||||||
|
||||||
const containerFilePath = '/root/message-file-path'; | ||||||
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. Nit:
Suggested change
|
||||||
|
||||||
try { | ||||||
executeHostScriptIfPresent( | ||||||
{ | ||||||
MESSAGE_FILE_PATH: messageFilePath, | ||||||
}, | ||||||
proposal, | ||||||
'before-test-run.sh', | ||||||
); | ||||||
|
||||||
console.log(`Running test image for proposal ${proposal.proposalName}`); | ||||||
const { name } = imageNameForProposal(proposal, 'test'); | ||||||
spawnSync( | ||||||
'docker', | ||||||
[ | ||||||
'run', | ||||||
'--env', | ||||||
`MESSAGE_FILE_PATH=${containerFilePath}`, | ||||||
'--mount', | ||||||
`source=${messageFilePath},target=${containerFilePath},type=bind`, | ||||||
...(removeContainerOnExit ? ['--rm'] : []), | ||||||
...propagateSlogfile(process.env), | ||||||
...extraDockerArgs, | ||||||
name, | ||||||
], | ||||||
{ stdio: 'inherit' }, | ||||||
); | ||||||
|
||||||
executeHostScriptIfPresent( | ||||||
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. So at this point our tests are being executed inside container, right? |
||||||
{ | ||||||
MESSAGE_FILE_PATH: messageFilePath, | ||||||
}, | ||||||
proposal, | ||||||
'after-test-run.sh', | ||||||
); | ||||||
} finally { | ||||||
removeTempFileCallback(); | ||||||
} | ||||||
}; | ||||||
|
||||||
export const debugTestImage = (proposal: ProposalInfo) => { | ||||||
const { name } = imageNameForProposal(proposal, 'test'); | ||||||
console.log( | ||||||
` | ||||||
Starting chain of test image for proposal ${proposal.proposalName} | ||||||
|
||||||
To get an interactive shell in the container, use an IDE feature like "Attach Shell" or this command:' | ||||||
|
||||||
docker exec -ti $(docker ps -q -f ancestor=${name}) bash | ||||||
|
||||||
And within that shell: | ||||||
cd /usr/src/proposals/${proposal.path} && ./test.sh | ||||||
|
||||||
To edit files you can use terminal tools like vim, or mount the container in your IDE. | ||||||
In VS Code the command is: | ||||||
Dev Containers: Attach to Running Container... | ||||||
`, | ||||||
); | ||||||
|
||||||
const slogOpts = propagateSlogfile(process.env); | ||||||
// start the chain with ports mapped | ||||||
const cmd = `docker run ${slogOpts.join(' ')} --publish 26657:26657 --publish 1317:1317 --publish 9090:9090 --interactive --tty --entrypoint /usr/src/upgrade-test-scripts/start_agd.sh ${name}`; | ||||||
execSync(cmd, { stdio: 'inherit' }); | ||||||
return runTestImage({ | ||||||
extraDockerArgs: [ | ||||||
'--entrypoint', | ||||||
'/usr/src/upgrade-test-scripts/start_agd.sh', | ||||||
'--interactive', | ||||||
'--publish', | ||||||
'1317:1317', | ||||||
'--publish', | ||||||
'9090:9090', | ||||||
'--publish', | ||||||
'26657:26657', | ||||||
'--tty', | ||||||
], | ||||||
proposal, | ||||||
removeContainerOnExit: false, | ||||||
}); | ||||||
}; |
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.
Let's be more explicit about what the
host
folder is for. There has been some confusion: Agoric/agoric-sdk#10947 (comment)While you're at it a change like this would help,
This is not blocking feedback. If something is delayed by this PR the docs improvements can come 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.
Added