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

The test suite kills any process (including itself) if its path contains string 'dredd-hooks' (e.g. in dir name) #6

Closed
honzajavorek opened this issue Feb 10, 2016 · 2 comments · Fixed by #29

Comments

@honzajavorek
Copy link
Contributor

Running bundle exec cucumber outputs

$ bundle exec cucumber
Feature: Execution order

Killed: 9

on my computer (Mac). I debugged that it's caused by following lines in features/support/env.rb:

...
Before do
  puts "Killing server..."
  system "for i in `ps axu | grep 'server.rb' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"
  puts "Killing handler..."
  system "for i in `ps axu | grep 'dredd-hooks' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"
  ...

If I comment out the two "killing" lines, I can run Cucumber without problems, but then it seems to hang in the Feature: TCP server and messages / Scenario: Message exchange for event beforeEach / And I send a newline character as a message delimiter to the socket part:

Feature: TCP server and messages

  Scenario: TCP server                                       # features/tcp_server.feature:3
      Killing server...
      Killing handler...
    When I run `dredd-hooks-ruby` interactively              # vendor/bundle/ruby/2.0.0/gems/aruba-0.6.2/lib/aruba/cucumber.rb:113
    And I wait for output to contain "Starting"              # vendor/bundle/ruby/2.0.0/gems/aruba-0.6.2/lib/aruba/cucumber.rb:131
    Then It should start listening on localhost port "61321" # features/step_definitions/dredd_steps.rb:13

  Scenario: Message exchange for event beforeEach                       # features/tcp_server.feature:8
      Killing server...
      Killing handler...
    Given I run `dredd-hooks-ruby` interactively                        # vendor/bundle/ruby/2.0.0/gems/aruba-0.6.2/lib/aruba/cucumber.rb:113
    When I wait for output to contain "Starting"                        # vendor/bundle/ruby/2.0.0/gems/aruba-0.6.2/lib/aruba/cucumber.rb:131
    And I connect to the server                                         # features/step_definitions/dredd_steps.rb:18
    And I send a JSON message to the socket:                            # features/step_definitions/dredd_steps.rb:22
      """
      {"event": "beforeEach", "uuid": "1234-abcd", "data": {"key":"value"}}
      """
    And I send a newline character as a message delimiter to the socket # features/step_definitions/dredd_steps.rb:27

Nothing gets printed since that moment for very long time and I have to eventually interrupt Cucumber with Ctrl+C.

@honzajavorek
Copy link
Contributor Author

Looks like it's because the PID search isn't very bulletproof. If my working folder contains string dredd-hooks, then any running process will be matched and killed.

$ ps axu | grep 'dredd-hooks' | grep ruby
honzajavorek    43086 100.0  0.1  2471588  16520 s003  R+    3:39PM   4:40.68 ruby /Users/honzajavorek/Workspace/dredd-hooks-ruby/bin/dredd-hooks-ruby
honzajavorek    43036   0.0  0.2  2483232  30648 s003  S+    3:39PM   0:00.66 ruby /Users/honzajavorek/Workspace/dredd-hooks-ruby/vendor/bundle/ruby/2.0.0/bin/cucumber

Workaround:

puts "Killing server..."
system "for i in `ps axu | grep 'server.rb' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"
puts "Killing handler..."
system "for i in `ps axu | grep 'dredd-hooks' | grep -v 'cucumber' | grep ruby | awk '{print $2}'`; do kill -9 $i; done > /dev/null 2>&1"

(See the grep -v 'cucumber' I added.) With such fix the tests run and pass correctly.

@honzajavorek honzajavorek changed the title The test suite probably kills itself under some circumstances The test suite kills any process (including itself) if its path contains string 'dredd-hooks' (e.g. in dir name) Feb 10, 2016
gonzalo-bulnes added a commit to apiaryio/dredd-hooks-ruby that referenced this issue Jan 26, 2017
I had removed it in c9c31d9

This version of the scripts should also fix the Travis CI build:
see apiaryio/dredd-hooks-template#6 (comment)
gonzalo-bulnes added a commit to apiaryio/dredd-hooks-ruby that referenced this issue Jan 26, 2017
I had removed it in c9c31d9

This version of the scripts should also fix the Travis CI build:
see apiaryio/dredd-hooks-template#6 (comment)
gonzalo-bulnes added a commit to apiaryio/dredd-hooks-ruby that referenced this issue Jan 26, 2017
Prevent Cucumber from being killed prematurely.
Curiously, the workaround descibed in apiaryio/dredd-hooks-template#6 (comment)
did not work... and more curiously, not killing the handler
doesn't seem to disturb the following scenarios.
This was referenced Apr 23, 2019
@ApiaryBot
Copy link
Collaborator

🎉 This issue has been resolved in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants