shell_directive: fix race condition when running commands
ClosedPublic

Authored by kparal on Aug 22 2016, 2:58 PM.

Details

Summary

Even though some commands exited with non-zero exit code, we sometimes
believed it exited with zero code due to a race condition. This patch
fixes that and also moves the code to a separate function
run_and_print in os_utils.

Test Plan

in order to test this, first reproduce the issue on existing code base. Apply this patch:

diff --git a/testing/functest_shell_directive.py b/testing/functest_shell_directive.py
index a1cc0f6..81a19e9 100644
--- a/testing/functest_shell_directive.py
+++ b/testing/functest_shell_directive.py
@@ -69,7 +69,11 @@ class TestCheckCommand(object):

         assert output == OUTPUT

-    def test_multi_command_error(self):
+    @pytest.fixture(params=xrange(1000))
+    def moore(self, request):
+        return
+
+    def test_multi_command_error(self, moore):
         test_params = ['true',
                        'echo -n %s' % OUTPUT[::-1],
                        'false',

and then run the test suite like this:

py.test -F testing/functest_shell_directive.py -x -k test_multi_command_error

During the execution, open up a new terminal and run yes command in order to simulate some load on your machine (or do something else to cause larger load on the machine). In my case, the race condition is triggered (and the test suite fails) immediately after running yes.

Now apply the patch and try the same with new codebase. It should no longer happen.

Diff Detail

Repository
rLTRN libtaskotron
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
kparal retitled this revision from to shell_directive: fix race condition when running commands.Aug 22 2016, 2:58 PM
kparal updated this object.
kparal edited the test plan for this revision. (Show Details)
kparal added reviewers: libtaskotron, lbrabec.
kparal updated this object.Aug 22 2016, 2:59 PM
kparal updated this revision to Diff 2508.Aug 23 2016, 8:11 AM
  • bikeshedding: rename run_and_print to popen_rt
This revision is now accepted and ready to land.Aug 23 2016, 9:14 AM
This revision was automatically updated to reflect the committed changes.