Skip to content
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

fix: cli tests randomly fail #469

Merged
merged 22 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 105 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ on:
pull_request: {}
workflow_call: {}
jobs:
build:
unit-tests:
runs-on: ubuntu-latest
env:
CI: "true"
Expand All @@ -13,8 +13,7 @@ jobs:
- uses: ./.github/actions/build
- name: Run tests
run: pnpm test
test-runtime:
needs: [build]
deploy-runtime:
concurrency: pr-test-runtime
runs-on: ubuntu-latest
permissions:
Expand All @@ -35,8 +34,35 @@ jobs:
run: pnpm -r --filter tests-runtime run deploy:runtime
env:
EVENTUAL_LOCAL: "1"
- name: Upload deployment output as artifact
uses: actions/upload-artifact@v3
with:
name: deployment-output
path: ./apps/tests/aws-runtime/cdk.out/outputs.json
test-runtime:
needs: [deploy-runtime]
concurrency: pr-test-runtime
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::593491530938:role/githubActionStack-githubactionroleA106E4DC-14SHKLVA61IN4
aws-region: us-east-1
role-duration-seconds: 3600
- name: Download artifact with variable
id: deployment-output
uses: actions/download-artifact@v3
with:
name: deployment-output
path: deployment
- run: |
echo "TEST_ROLE_ARN=$(node -p 'JSON.parse(require("fs").readFileSync("./apps/tests/aws-runtime/cdk.out/outputs.json"))["eventual-tests"].roleArn')" >> $GITHUB_ENV
echo "TEST_ROLE_ARN=$(node -p 'JSON.parse(require("fs").readFileSync("${{ steps.deployment-output.outputs.download-path }}/outputs.json"))["eventual-tests"].roleArn')" >> $GITHUB_ENV
- name: Configure Test Role Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
Expand All @@ -47,14 +73,86 @@ jobs:
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
role-skip-session-tagging: true
- name: Run Local Tests
run: pnpm -r --filter tests-runtime run test:local-start
role-session-name: ${{ github.job }}
- name: Run Runtime Tests
run: pnpm -r --filter tests-runtime run test:runtime
env:
OUTPUTS_FILE: "${{ steps.deployment-output.outputs.download-path }}/outputs.json"
test-local:
needs: [deploy-runtime]
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::593491530938:role/githubActionStack-githubactionroleA106E4DC-14SHKLVA61IN4
aws-region: us-east-1
role-duration-seconds: 3600
- name: Download artifact with variable
id: deployment-output
uses: actions/download-artifact@v3
with:
name: deployment-output
path: deployment
- run: |
echo "TEST_ROLE_ARN=$(node -p 'JSON.parse(require("fs").readFileSync("${{ steps.deployment-output.outputs.download-path }}/outputs.json"))["eventual-tests"].roleArn')" >> $GITHUB_ENV
- name: Configure Test Role Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ env.TEST_ROLE_ARN }}
aws-region: us-east-1
role-duration-seconds: 3600
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
role-skip-session-tagging: true
role-session-name: ${{ github.job }}
- name: Run Local Tests
run: pnpm -r --filter tests-runtime run test:local-start
test-cli:
needs: [test-runtime]
runs-on: ubuntu-latest
env:
CI: "true"
permissions:
contents: write
id-token: write
steps:
- uses: actions/checkout@v3
- uses: ./.github/actions/build
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: arn:aws:iam::593491530938:role/githubActionStack-githubactionroleA106E4DC-14SHKLVA61IN4
aws-region: us-east-1
role-duration-seconds: 3600
- name: Download artifact with variable
id: deployment-output
uses: actions/download-artifact@v3
with:
name: deployment-output
path: deployment
- run: |
echo "TEST_ROLE_ARN=$(node -p 'JSON.parse(require("fs").readFileSync("${{ steps.deployment-output.outputs.download-path }}/outputs.json"))["eventual-tests"].roleArn')" >> $GITHUB_ENV
- name: Configure Test Role Credentials
uses: aws-actions/configure-aws-credentials@v1-node16
with:
role-to-assume: ${{ env.TEST_ROLE_ARN }}
aws-region: us-east-1
role-duration-seconds: 3600
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }}
aws-session-token: ${{ env.AWS_SESSION_TOKEN }}
role-skip-session-tagging: true
role-session-name: ${{ github.job }}
- name: Run CLI Tests
run: pnpm -r --filter tests-runtime run test:cli
test-create:
needs: [build]
runs-on: ubuntu-latest
permissions:
contents: write
Expand Down
2 changes: 1 addition & 1 deletion apps/tests/aws-runtime-cdk/src/chaos-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export class ChaosExtension extends Construct {
/**
* Grant the ability to read and write the SSM parameter used by the chaos extension.
*
* This is required to use the {@link SSMChaosClient}.
* This is required to use the {@link ChaosClient}.
*/
public grantReadWrite(grantable: IGrantable) {
this.ssm.grantRead(grantable);
Expand Down
2 changes: 1 addition & 1 deletion apps/tests/aws-runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"version": "0.0.0",
"main": "lib/test-service.js",
"scripts": {
"test:runtime": "NODE_OPTIONS=--experimental-vm-modules OUTPUTS_FILE=cdk.out/outputs.json jest --passWithNoTests",
"test:runtime": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
"test:local": "NODE_OPTIONS=--experimental-vm-modules TEST_LOCAL=1 jest --passWithNoTests",
"test:cli": "./scripts/test-cli",
"test:create": "./scripts/test-create",
Expand Down
2 changes: 2 additions & 0 deletions apps/tests/aws-runtime/scripts/test-cli
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ npx eventual start workflow sleepy -f

npx eventual list executions

mkdir -p .eventual

npx eventual list executions --workflow sleepy --json > .eventual/out.json

execution_id=$(node -p 'JSON.parse(require("fs").readFileSync(".eventual/out.json").toString("utf8")).executions[0].id')
Expand Down
2 changes: 2 additions & 0 deletions packages/@eventual/aws-cdk/src/command-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ export class CommandService<Service = any> {
this.props.build.system.eventualService.systemCommandHandler,
functionNameSuffix: "system-command",
serviceName: this.props.serviceName,
// the logs command is the outlier here. Was often timing out at 3 seconds.
defaults: { timeout: Duration.seconds(30) },
}
);

Expand Down
15 changes: 10 additions & 5 deletions packages/@eventual/cli/src/commands/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ export const logs = (yargs: Argv) =>
};

do {
const fetchResult = await fetchLogs(logFilter, logCursor);
logCursor = updateLogCursor(logCursor, fetchResult, follow);
try {
const fetchResult = await fetchLogs(logFilter, logCursor);
logCursor = updateLogCursor(logCursor, fetchResult, follow);
} catch (err) {
console.error(err);
throw err;
}

if (follow) {
spinner.start("Watching logs");
Expand All @@ -105,20 +110,20 @@ export const logs = (yargs: Argv) =>
? new Date(logCursor.startTime).toISOString()
: undefined,
workflowName: logFilter.workflowName,
maxResults: 1000,
});

const functionEvents = output.events ?? [];

// Print out the interleaved logs
if (functionEvents.length) {
spinner.stop();
functionEvents.forEach((ev) => {
console.log(
process.stdout.write(
`${
logFilter.executionId ? "" : `[${chalk.blue(ev.source)}] `
}${chalk.red(new Date(ev.time!).toLocaleString())} ${
ev.message
}`
}\n`
);
});
}
Expand Down