Skip to content

Commit 1b99e01

Browse files
Merge pull request #208 from bugsnag/tms/idempotent-commands
Preparation for using Maze Runner idempotent commands
2 parents 6335aff + fedab48 commit 1b99e01

File tree

4 files changed

+70
-67
lines changed

4 files changed

+70
-67
lines changed

.buildkite/unity.6000.full.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ agents:
77
steps:
88
- group: ":hammer: Build Unity 6000 Test Fixtures"
99
steps:
10-
- label: ':macos: Build macos test fixture for Unity 2022'
10+
- label: ':macos: Build macos test fixture for Unity 6000'
1111
timeout_in_minutes: 30
1212
key: build-macos-fixture-6000
1313
depends_on: build-artifacts

features/persistence.feature

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ Feature: Trace and state persistence
1111
And the trace "Bugsnag-Span-Sampling" header equals "1:3"
1212
And I wait for requests to persist
1313
And I discard the oldest trace
14-
And I close the Unity app
14+
And I stop the Unity app
1515
Then I set the HTTP status code to 200
16-
And I relaunch the app
16+
And I start the Unity app
1717
And I run the game in the "StartSDK" state
1818
And I wait to receive at least 3 spans
1919
And the trace "Bugsnag-Span-Sampling" header equals "1:3"
@@ -27,9 +27,9 @@ Feature: Trace and state persistence
2727
And the trace "Bugsnag-Span-Sampling" header equals "1:3"
2828
And I wait for requests to persist
2929
And I discard the oldest trace
30-
And I close the Unity app
30+
And I stop the Unity app
3131
Then I set the HTTP status code to 200
32-
And I relaunch the app
32+
And I start the Unity app
3333
And I run the game in the "MaxBatchAge" state
3434
And I should receive no trace
3535

@@ -40,10 +40,10 @@ Feature: Trace and state persistence
4040
And I run the game in the "PValueUpdate" state
4141
And I wait to receive a sampling request
4242
Then I should receive no traces
43-
Then I close the Unity app
43+
Then I stop the Unity app
4444
# Block the next initial P value request so that it keeps its 0.0 P value
4545
And I set the HTTP status code for the next request to 404
46-
And I relaunch the app
46+
And I start the Unity app
4747
And I run the game in the "PValueUpdate" state
4848
Then I should receive no traces
4949

@@ -54,9 +54,9 @@ Feature: Trace and state persistence
5454
And I run the game in the "PValueUpdate" state
5555
And I wait to receive a sampling request
5656
Then I should receive no traces
57-
Then I close the Unity app
57+
Then I stop the Unity app
5858
And I set the sampling probability for the next traces to "1"
59-
And I relaunch the app
59+
And I start the Unity app
6060
And I run the game in the "PValueUpdate" state
6161
And I wait to receive at least 1 span
6262
And the trace "Bugsnag-Span-Sampling" header equals "1:1"
@@ -70,10 +70,10 @@ Feature: Trace and state persistence
7070
And the trace "Bugsnag-Span-Sampling" header equals "1:1"
7171
And I wait for requests to persist
7272
And I discard the oldest trace
73-
Then I close the Unity app
73+
Then I stop the Unity app
7474
# Block the next initial P value request so that it keeps its 1.0 P value
7575
And I set the HTTP status code for the next request to 404
76-
And I relaunch the app
76+
And I start the Unity app
7777
And I run the game in the "PValueUpdate" state
7878
And I wait to receive at least 1 span
7979
And the trace "Bugsnag-Span-Sampling" header equals "1:1"
@@ -87,9 +87,9 @@ Feature: Trace and state persistence
8787
And the trace "Bugsnag-Span-Sampling" header equals "1:1"
8888
And I wait for requests to persist
8989
And I discard the oldest trace
90-
Then I close the Unity app
90+
Then I stop the Unity app
9191
And I set the sampling probability for the next traces to "0"
92-
And I relaunch the app
92+
And I start the Unity app
9393
And I run the game in the "PValueUpdate" state
9494
Then I should receive no traces
9595

features/steps/unity_steps.rb

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,37 +15,16 @@ def execute_command(action, scenario_name = '')
1515

1616
When('I clear the Bugsnag cache') do
1717
case Maze::Helper.get_current_platform
18-
when 'macos', 'webgl'
19-
# Call executable directly rather than use open, which flakes on CI
20-
log = File.join(Dir.pwd, 'clear_cache.log')
21-
command = "#{Maze.config.app}/Contents/MacOS/Mazerunner --args -logfile #{log} > /dev/null"
22-
Maze::Runner.run_command(command, blocking: false)
23-
execute_command('clear_cache')
24-
25-
when 'windows'
26-
win_log = File.join(Dir.pwd, 'clear_cache.log')
27-
command = "#{Maze.config.app} --args -logfile #{win_log}"
28-
Maze::Runner.run_command(command, blocking: false)
29-
execute_command('clear_cache')
30-
31-
when 'android', 'ios'
18+
when 'macos', 'windows', 'android', 'ios', 'switch'
3219
execute_command('clear_cache')
3320
when 'browser'
3421
url = "http://localhost:#{Maze.config.port}/docs/index.html"
3522
$logger.debug "Navigating to URL: #{url}"
3623
step("I navigate to the URL \"#{url}\"")
3724
execute_command('clear_cache')
38-
39-
when 'switch'
40-
switch_run_on_target
41-
execute_command('clear_cache')
42-
4325
else
4426
raise "Platform #{platform} has not been considered"
4527
end
46-
47-
sleep 2
48-
4928
end
5029

5130
When('I run the game in the {string} state') do |state|
@@ -90,16 +69,6 @@ def execute_command(action, scenario_name = '')
9069
sleep 2
9170
end
9271

93-
When('I relaunch the app') do
94-
next unless Maze.config.device
95-
Maze::Api::Appium::AppManager.new.launch
96-
sleep 3
97-
end
98-
99-
When('I close the Unity app') do
100-
execute_command('close_application')
101-
end
102-
10372
Then("the span named {string} has a minimum duration of {int}") do |span_name,duration|
10473

10574
spans = spans_from_request_list(Maze::Server.list_for("traces"))
@@ -298,3 +267,55 @@ def check_valid_percentage(value, field_name, attribute_name, request_type)
298267
"Expected '#{field_name}' to have at least #{min_count} elements in request type '#{request_type}', but got #{actual_count}"
299268
)
300269
end
270+
271+
When('I stop the Unity app') do
272+
stop_app
273+
end
274+
275+
When('I start the Unity app') do
276+
start_app
277+
end
278+
279+
def start_app
280+
platform = Maze::Helper.get_current_platform
281+
case platform
282+
when 'macos'
283+
# Open the fixture - call executable directly rather than use open, which flakes on CI
284+
command = "#{Maze.config.app}/Contents/MacOS/Mazerunner --args > /dev/null"
285+
Maze::Runner.run_command(command, blocking: false)
286+
when 'windows'
287+
command = "#{Maze.config.app}"
288+
Maze::Runner.run_command(command, blocking: false)
289+
when 'android', 'ios'
290+
manager = Maze::Api::Appium::AppManager.new
291+
manager.activate
292+
when 'switch'
293+
switch_run_on_target
294+
when 'browser'
295+
# WebGL - do nothing
296+
else
297+
raise "Platform #{platform} has not been considered"
298+
end
299+
end
300+
301+
def stop_app
302+
platform = Maze::Helper.get_current_platform
303+
case platform
304+
when 'macos'
305+
`killall Mazerunner`
306+
when 'windows'
307+
# This assumes Maze Runner is being run under WSL
308+
process_name = File.basename(Maze.config.app)
309+
`/mnt/c/Windows/system32/taskkill.exe /F /IM #{process_name}`
310+
when 'android', 'ios'
311+
manager = Maze::Api::Appium::AppManager.new
312+
manager.terminate
313+
when 'switch'
314+
# Terminate the app
315+
Maze::Runner.run_command('ControlTarget.exe terminate')
316+
when 'browser'
317+
# WebGL - do nothing
318+
else
319+
raise "Platform #{platform} has not been considered"
320+
end
321+
end

features/support/env.rb

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,5 @@
11
require 'fileutils'
22

3-
Before('@skip_unity_2018') do |_scenario|
4-
if ENV['UNITY_VERSION']
5-
unity_version = ENV['UNITY_VERSION'][0..3].to_i
6-
if unity_version == 2018
7-
skip_this_scenario('Skipping scenario on Unity 2018')
8-
end
9-
end
10-
end
11-
12-
133
Before('@skip_webgl') do |_scenario|
144
skip_this_scenario('Skipping scenario') unless Maze.config.browser.nil?
155
end
@@ -126,23 +116,15 @@
126116
$logger.info 'Killing defaults service'
127117
Maze::Runner.run_command("killall -u #{ENV['USER']} cfprefsd")
128118
end
119+
120+
platform = Maze::Helper.get_current_platform
121+
start_app unless platform in ['android', 'ios'] # Maze Runner will handle mobile platforms
129122
end
130123

131124
After do |scenario|
132125
next if scenario.status == :skipped
133126

134-
case Maze::Helper.get_current_platform
135-
when 'macos'
136-
`killall Mazerunner`
137-
when 'windows'
138-
Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /IM mazerunner_windows.exe || exit 0")
139-
Maze::Runner.run_command("/mnt/c/Windows/system32/taskkill.exe /IM mazerunner_windows_dev.exe || exit 0")
140-
when 'webgl'
141-
execute_command('close_application')
142-
when 'switch'
143-
# Terminate the app
144-
Maze::Runner.run_command('ControlTarget.exe terminate')
145-
end
127+
stop_app
146128
end
147129

148130
AfterAll do

0 commit comments

Comments
 (0)