Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

test(automatic-releases): smoke tests failed if "input.files" contains existing files #379

Open
pzhlkj6612 opened this issue Feb 1, 2022 · 0 comments

Comments

@pzhlkj6612
Copy link
Contributor

Firstly, let's make the following changes based on 9ecff5f :

git diff
diff --git a/packages/automatic-releases/__tests__/utils/mockNewReleaseTag.ts b/packages/automatic-releases/__tests__/utils/mockNewReleaseTag.ts
index dcb1fa9..f353abc 100644
--- a/packages/automatic-releases/__tests__/utils/mockNewReleaseTag.ts
+++ b/packages/automatic-releases/__tests__/utils/mockNewReleaseTag.ts
@@ -11,5 +11,5 @@ const testInputDraft = false;
 const testInputPrerelease = true;
 const testInputTitle = 'Development Build';
-const testInputFiles = 'file1.txt\nfile2.txt\n*.jar\n\n';
+const testInputFiles = `${path.join(__dirname, '../assets/LICENSE')}\n${path.join(__dirname, '../assets/*.jar')}\n\n`;
 
 server.get(`/repos/marvinpinto/private-actions-tester/compare/HEAD...${testGhSHA}`, (req, res) => {
diff --git a/packages/automatic-releases/__tests__/utils/mockNewTaggedRelease.ts b/packages/automatic-releases/__tests__/utils/mockNewTaggedRelease.ts
index 75fd203..3385d2a 100644
--- a/packages/automatic-releases/__tests__/utils/mockNewTaggedRelease.ts
+++ b/packages/automatic-releases/__tests__/utils/mockNewTaggedRelease.ts
@@ -9,5 +9,5 @@ const testGhSHA = 'f6f40d9fbd1130f7f2357bb54225567dbd7a3793';
 const testInputDraft = false;
 const testInputPrerelease = true;
-const testInputFiles = 'file1.txt\nfile2.txt\n*.jar\n\n';
+const testInputFiles = `${path.join(__dirname, '../assets/LICENSE')}\n${path.join(__dirname, '../assets/*.jar')}\n\n`;
 
 server.get(`/repos/marvinpinto/private-actions-tester/tags`, (req, res) => {
diff --git a/packages/automatic-releases/__tests__/utils/mockUpdateExistingTag.ts b/packages/automatic-releases/__tests__/utils/mockUpdateExistingTag.ts
index f898cde..4f6090c 100644
--- a/packages/automatic-releases/__tests__/utils/mockUpdateExistingTag.ts
+++ b/packages/automatic-releases/__tests__/utils/mockUpdateExistingTag.ts
@@ -11,5 +11,5 @@ const testInputDraft = false;
 const testInputPrerelease = true;
 const testInputTitle = 'Development Build';
-const testInputFiles = 'file1.txt\nfile2.txt\n*.jar\n\n';
+const testInputFiles = `${path.join(__dirname, '../assets/LICENSE')}\n${path.join(__dirname, '../assets/*.jar')}\n\n`;
 
 const previousReleaseSHA = '4398ef4ea6f5a61880ca94ecfb8e60d1a38497dd';

Please note that we do have two files ("LICENSE" and "test.jar") that match the above two globs.

Then, build "automatic-releases" and test it:

(to avoid huge and useless error report, you may need to change optimization.minimize to false in "packages/automatic-releases/webpack.config.js" temporarily)

$ yarn build --scope=automatic-releases && clear && GITHUB_ACTIONS=true yarn test automatic-releases --testNamePattern=smoke --verbose
yarn run v1.22.17
$ yarn jest --env=node --colors automatic-releases --testNamePattern=smoke --verbose
$ /home/ubuntu/actions/node_modules/.bin/jest --env=node --colors automatic-releases --testNamePattern=smoke --verbose
...
 FAIL   automatic-releases  packages/automatic-releases/__tests__/automaticReleases-smoke.test.ts
  automatic releases smoke tests
    ✕ should create a new release tag (789 ms)
    ✕ should update an existing release tag (511 ms)

  ● automatic releases smoke tests › should create a new release tag

    Command failed: /tmp/yarn--1643715452751-0.7636044769559776/node /tmp/ghactions-pWazxx/index.js
    (node:13079) UnhandledPromiseRejectionWarning: HttpError: request to https://releaseupload.example.com/ failed, reason: getaddrinfo ENOTFOUND releaseupload.example.com releaseupload.example.com:443

    ...stacktrace

  ● automatic releases smoke tests › should update an existing release tag

    Command failed: /tmp/yarn--1643715452751-0.7636044769559776/node /tmp/ghactions-TNi1qv/index.js
    (node:13093) UnhandledPromiseRejectionWarning: HttpError: request to https://releaseupload.example.com/ failed, reason: getaddrinfo ENOTFOUND releaseupload.example.com releaseupload.example.com:443

    ...stacktrace

 FAIL   automatic-releases  packages/automatic-releases/__tests__/taggedReleases-smoke.test.ts
  tagged releases smoke tests
    ✕ should create a new release (509 ms)

  ● tagged releases smoke tests › should create a new release

    Command failed: /tmp/yarn--1643715452751-0.7636044769559776/node /tmp/ghactions-ZweEYz/index.js
    (node:13109) UnhandledPromiseRejectionWarning: HttpError: request to https://releaseupload.example.com/ failed, reason: getaddrinfo ENOTFOUND releaseupload.example.com releaseupload.example.com:443

    ...stacktrace

...
Test Suites: 2 failed, 4 skipped, 2 of 6 total
Tests:       3 failed, 13 skipped, 16 total
Snapshots:   0 total
Time:        6.318 s, estimated 8 s
Ran all test suites matching /automatic-releases/i with tests matching "smoke".
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.

As you can see, something does not work. After some tests, I think I've found the reason:

  1. The dummy website URL (https://releaseupload.example.com) in mockNewReleaseTag.ts, mockNewTaggedRelease.ts and mockUpdateExistingTag.ts is fetched by "createRelease()" and used as the target of uploadReleaseAsset() in uploadReleaseArtifacts(). uploadReleaseAsset() wants to send a POST request to that website, but apparently, no one could handle the request.
  2. Those smoke tests have passed in the past few years because uploadReleaseArtifacts() didn't fail if a file glob doesn't match anything. If there is a mismatch glob, uploadReleaseArtifacts() will silently return. Thus, most of the code in "uploadReleaseArtifacts.ts" has not been tested. Those are not qualified smoke tests, I think.

So,

  1. Handling the request is the responsibility of our mock website (i.e., the "Express.js" server). To fix this, we need to make the upload_url field contain a reachable URL.
  2. We already have Report error if a file glob doesn't match anything #63 , but it's not enough, or say, it's misleading. core.error is just a logging function and it won't throw anything, so the error handling code at main.ts#L321-L323 would not work in this case. We need to change the behavior of uploadReleaseArtifacts() .
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant