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: start detached and stop cleanup #403

Merged
merged 11 commits into from
Oct 28, 2019
Merged

fix: start detached and stop cleanup #403

merged 11 commits into from
Oct 28, 2019

Conversation

wwilsman
Copy link
Contributor

@wwilsman wwilsman commented Oct 25, 2019

Purpose

An issue was brought up where the start and stop commands did not work as expected with the latest version of agent. In fixing that issue, I discovered that our test suite was not finishing and was exiting with a 0 status early.

After digging through CircleCI builds, I am unable to determine when these tests started to not be run in CI. It seem the very fist passing build has a warning about Percy exiting. Previous test runs cannot be viewed due to the junit mocha reporter only saving reports to a file.

Approach

  • Defaulted healthcheck helper argument to the default port and also made use of the healthcheck endpoint constant.

  • Since flags no longer have defaults, we were passing the string "undefined" into the detached start process. This was fixed by conditionally setting those flags.

  • The stop endpoint finalized the build, closed the server, and killed the running process. That last part caused builds to be re-finalized, therefore creating empty duplicate builds. This was fixed by cleaning up the PID file rather than outright killing the process. Since the server closes, the process will close anyway.

  • Use the oclif this.exit method. Using process.exit caused the mocha process to exit. Oclif exit stops script execution by throwing an error, so callbacks that referenced the stop method had to be adjusted.

    • Shared process handlers now pass a boolean to exit the process
    • The other call to stop in exec needed to be moved out of the callbacks and called after the subprocess exited. This subprocess was turned into a promise so that errors can be caught and we can always call close without creating an unhandled rejection.
    • The stdio test helpers were updated to ignore safe oclif exits
  • All failing tests were fixed and updated. Even the skipped exec tests can be re-enabled. A couple of tests were removed due to them never working or being superseded by another change.

  • Finally, junit was removed as the sole reporter so we can actually see the results of our tests in CI.

Also use the HEALTHCHECK_PATH constant in this helper
The process has handlers to finalize on SIGHUP, but the stop request already
finalizes the build before sending SIGHUP. Sometimes this caused duplicate,
empty, builds due to the finalize method creating a build when the current build
has already been finalized.
Testing with `process.exit` causes the test process to exit
This command was hard to test due to the subprocess being spawn async. In
practice the parent process remains open as well, but for our tests this method
returned before the command was finished.
These tests previously caused the entire suite to exit early. Once that was
fixed, the two tests written with the oclif helper failed.

One was updated to not need the helper, and the other test was removed since the
snapshot command now has a default directory argument.
This agent test caused many other tests to fail since it mutated the
DEFAULT_CONFIGURATION object.
With recent bug fixes, these tests can be unskipped and actually run.

The 'echo' test was replaced with 'sleep' to avoid printing to the inherited
stdio of the test process.

An unfinished test was fleshed out, and the other unfinished test removed since
exec does not support that behavior.
When the tests exited early or threw warnings and logs, it went unnoticed in CI
since junit reports to a file. Circle only shows tests when they fail, so passed
tests or missed tests were never shown.
@wwilsman wwilsman requested a review from Robdel12 October 25, 2019 23:09
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁 Nice work. Getting skipped tests back into the suite and working is always good.

@@ -29,7 +29,7 @@ commands:
name: Unit tests
command: |
mkdir -p reports
$NYC yarn test --reporter mocha-junit-reporter
$NYC yarn test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we lose the junit output entirely? It's nice to use Circles reporting from the junit reporter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately with mocha, you can technically only have a single reporter. A junit file reporter for Circle failure reporting or being able to see successful CI output using the default reporter?

We could implement a third-party reporter like mocha-multi-reporters, but I thought that could be another PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that could be another PR. Wanna create a clubhouse / GH issue (whichever)?

@Robdel12
Copy link
Contributor

Maybe we should update the title to reflect better in the changelog? Something that includes fixing the --detached flag maybe?

@wwilsman
Copy link
Contributor Author

This fixes more than just --detached though even those that's where this originated. It also fixes the agent server / stop command from finalizing a build twice, but I suppose other than that the other fixes are test-related.

@wwilsman wwilsman changed the title fix: tests and bugs fix: start detached and stop cleanup Oct 28, 2019
Copy link
Contributor

@Robdel12 Robdel12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏁

@wwilsman wwilsman merged commit 2b4662e into master Oct 28, 2019
@wwilsman wwilsman deleted the ww/fix-tests-and-bugs branch October 28, 2019 19:56
djones pushed a commit that referenced this pull request Oct 28, 2019
## [0.19.2](v0.19.1...v0.19.2) (2019-10-28)

### Bug Fixes

* start detached and stop cleanup ([#403](#403)) ([2b4662e](2b4662e))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants