Discussion:
[Cucumber] [Ruby] Run same scenario multiple times
(too old to reply)
Larry Reaves
2018-02-28 23:01:34 UTC
Permalink
I am attempting to use cucumber to help orchestrate some load tests. What
I would like to achieve is to describe a scenario once and have it run N
times in parallel. My initial attempt was this:

Around('@performance') do |scenario, block|

count = ENV['CUKE_USER_COUNT'] || 5


threads = []

(1..count).each do |n|

threads << Thread.new do

thread = Thread.current

thread[:username] = "test#{n}"

Capybara.using_session(thread[:username]) do

session_setup

block.call

end

end

end


threads.each do |t|

t.join

end

end

When setting CUKE_USER_COUNT to 1, it works perfectly. However, more than
1 user causes it to blow up in one of a variety of locations. I'm suppose
that the block passed into the around hook interacts with the test runner
state in a way that makes it unsafe to call multiple times. Is there a
simple way to achieve the desired effect, or will I need to implement a
custom test runner? If I do need to implement a custom test runner, any
links to documentation or tutorials on low-level cucumber-ruby guts would
be appreciated.

Thank you,
Larry Reaves
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Larry Reaves
2018-03-01 14:44:20 UTC
Permalink
Post by Larry Reaves
I am attempting to use cucumber to help orchestrate some load tests. What
I would like to achieve is to describe a scenario once and have it run N
count = ENV['CUKE_USER_COUNT'] || 5
threads = []
(1..count).each do |n|
threads << Thread.new do
thread = Thread.current
thread[:username] = "test#{n}"
Capybara.using_session(thread[:username]) do
session_setup
block.call
end
end
end
threads.each do |t|
t.join
end
end
When setting CUKE_USER_COUNT to 1, it works perfectly. However, more than
1 user causes it to blow up in one of a variety of locations. I'm suppose
that the block passed into the around hook interacts with the test runner
state in a way that makes it unsafe to call multiple times. Is there a
simple way to achieve the desired effect, or will I need to implement a
custom test runner? If I do need to implement a custom test runner, any
links to documentation or tutorials on low-level cucumber-ruby guts would
be appreciated.
Thank you,
Larry Reaves
I have resolved this:

Around('@performance') do |scenario, block|

count = ENV['CUKE_USER_COUNT'] || 5


processes = []

(1..count).each do |n|

runner = lambda do

thread = Thread.current

thread[:username] = "test#{n}"

Capybara.using_session(thread[:username].to_sym) do

session_setup

block.call

end

end

if n == count

runner.call

else

processes << fork do

runner.call

end

end

end


processes.each do |p|

Process.waitpid(p)

end
end

Rather than using threads, I fork a new process for each test session
except the Nth. The Nth session runs in the current process. Cucumber
only reports results for this session, but that is fine for my usage since
I will be collecting stats from the server logs.

-Larry
--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...