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

[3.4] fix: enable strict mode for CI #15504

Merged
merged 1 commit into from
Mar 23, 2023
Merged

Conversation

fuweid
Copy link
Member

@fuweid fuweid commented Mar 18, 2023

By default, the pipefail is disabled. For instance, the commands should
return 1 as exit code, but we get zero. After pipefail enabled, it's
back to normal.

And the test.log is used to grep the error from a ton of messages. So
that we should set +e and set it back after egrep.

fixes: #15487

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.


1. If failed to build: https://github.com/etcd-io/etcd/actions/runs/4453530207/jobs/7822105485
2. If panic in the test: https://github.com/etcd-io/etcd/actions/runs/4453540829/jobs/7822123516

@ahrtr @serathius @jmhbnz

@fuweid fuweid force-pushed the fix-15487 branch 5 times, most recently from 3e2d228 to 9d7354f Compare March 18, 2023 04:00
@fuweid fuweid changed the title fix: use pipefail to show the error [3.4] fix: enable pipefail mode for grpcproxy test Mar 18, 2023
@fuweid fuweid marked this pull request as ready for review March 18, 2023 04:55
@@ -58,8 +58,12 @@ jobs:
GO_BUILD_FLAGS='-v' GOARCH=s390x ./build
;;
linux-amd64-grpcproxy)
set -o pipefail; set +e;
Copy link
Member Author

Choose a reason for hiding this comment

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

if it looks good, I will file a fix pr for main branch.

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM

To test I checked out this pr, pushed as a new branch with a bogus edit to a test file.
Opening a PR against 3.4 the workflow now correctly failed, refer: https://github.com/etcd-io/etcd/actions/runs/4454519493/jobs/7823765743?pr=15506

Thanks @fuweid 🙏🏻

Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

Good catch.

Thank you @fuweid

Usually we fix the main branch firstly, then backport to 3.5 & 3.4. But I won't insist on it for such a small change.

PASSES='build grpcproxy' CPU='4' RACE='true' ./test 2>&1 | tee test.log
! egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
ecode=$?
egrep "(--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked)" -B50 -A10 test.log
Copy link
Member

Choose a reason for hiding this comment

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

Why do you remove the ! ? We may need to keep it. If we find any (--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked), we may still consider the test failed.

Copy link
Member Author

@fuweid fuweid Mar 20, 2023

Choose a reason for hiding this comment

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

Sorry for the late reply.

I was thinking if we can delete the egrep command in this patch.

I didn't see any comment about egrep introduced in #8655.
It seems that the egrep is used to fix the unexpected exit code, since | tee won't return expected exit code because of pipefail.

As the tee already writes the log in the stdout, we won't lost any details and the command will return expected exit code. Maybe we can go with the following script:

set -o pipefail
PASSES='build grpcproxy' CPU='4' RACE='true' ./test 2>&1 | tee test.log

Does it make senses?

NOTE: In my opinion, if the test.log is not in the CI artifacts, we don't need the log file.

Copy link
Member

Choose a reason for hiding this comment

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

It should be OK, because the following case will never happen:
The test script/cases exits with 0, but somehow there are some (--- FAIL:|DATA RACE|panic: test timed out|appears to have leaked) errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. So I believe that egrep is to fix the pipefail issue. I will update the pr later and send new pr to main branch as well.

Copy link
Member

Choose a reason for hiding this comment

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

One of the things that first caught my eye in etcd scripting is fact that it doesn't run in strict mode and it even depends on some parts failing for correctness. By strict mode I mean set -euo pipefail as defined in http://redsymbol.net/articles/unofficial-bash-strict-mode/.

To my understanding !grep (--- FAIL:|... was a workaround for not properly written scripts. I think long term it would be better to fix all scripts and switch on strict mode. What do you think? @ahrtr @fuweid

Copy link
Member

Choose a reason for hiding this comment

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

By strict mode I mean set -euo pipefail as defined in

Makes sense to me.

Copy link
Member

@serathius serathius left a comment

Choose a reason for hiding this comment

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

It came to me while reviewing #15519.
We cannot just set set -o pipefail; set +e; in run as bash doesn't pass the flags we set to scripts it calls. This will only affect run and not ./test.

So this change doesn't work if ./test runs go test that writes --- FAIL: to stdout and doesn't exit with non-zero status code.

fixes: etcd-io#15487

Signed-off-by: Wei Fu <fuweid89@gmail.com>
@@ -588,6 +596,8 @@ function receiver_name_pass {
}

function commit_title_pass {
# TODO: git rev-parse --abbrev-ref doesn't work in pull-request and it
Copy link
Member Author

Choose a reason for hiding this comment

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

@fuweid fuweid changed the title [3.4] fix: enable pipefail mode for grpcproxy test [3.4] fix: enable strict mode for CI Mar 22, 2023
@fuweid fuweid marked this pull request as ready for review March 22, 2023 10:14
@fuweid
Copy link
Member Author

fuweid commented Mar 22, 2023

ping @serathius @ahrtr @jmhbnz please take a look. Thanks

@serathius
Copy link
Member

Can you prepare similar PR for v3.5?

@fuweid
Copy link
Member Author

fuweid commented Mar 23, 2023

Can you prepare similar PR for v3.5?

yeah. Still working on it. Will file it when it is ready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants