Skip to content

Commit 53a6159

Browse files
author
Steve Kirkland
committed
Change when test macOS fixture is opened and closed
1 parent 5cf14d0 commit 53a6159

File tree

3 files changed

+68
-44
lines changed

3 files changed

+68
-44
lines changed

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: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,16 +90,6 @@ def execute_command(action, scenario_name = '')
9090
sleep 2
9191
end
9292

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-
10393
Then("the span named {string} has a minimum duration of {int}") do |span_name,duration|
10494

10595
spans = spans_from_request_list(Maze::Server.list_for("traces"))
@@ -298,3 +288,55 @@ def check_valid_percentage(value, field_name, attribute_name, request_type)
298288
"Expected '#{field_name}' to have at least #{min_count} elements in request type '#{request_type}', but got #{actual_count}"
299289
)
300290
end
291+
292+
When('I stop the Unity app') do
293+
stop_app
294+
end
295+
296+
When('I start the Unity app') do
297+
start_app
298+
end
299+
300+
def start_app
301+
platform = Maze::Helper.get_current_platform
302+
case platform
303+
when 'macos'
304+
# Open the fixture - call executable directly rather than use open, which flakes on CI
305+
command = "#{Maze.config.app}/Contents/MacOS/Mazerunner --args > /dev/null"
306+
Maze::Runner.run_command(command, blocking: false)
307+
when 'windows'
308+
command = "#{Maze.config.app}"
309+
Maze::Runner.run_command(command, blocking: false)
310+
when 'android', 'ios'
311+
manager = Maze::Api::Appium::AppManager.new
312+
manager.activate
313+
when 'switch'
314+
switch_run_on_target
315+
when 'browser'
316+
# WebGL - do nothing
317+
else
318+
raise "Platform #{platform} has not been considered"
319+
end
320+
end
321+
322+
def stop_app
323+
platform = Maze::Helper.get_current_platform
324+
case platform
325+
when 'macos'
326+
`killall Mazerunner`
327+
when 'windows'
328+
# This assumes Maze Runner is being run under WSL
329+
process_name = File.basename(Maze.config.app)
330+
`/mnt/c/Windows/system32/taskkill.exe /F /IM #{process_name}`
331+
when 'android', 'ios'
332+
manager = Maze::Api::Appium::AppManager.new
333+
manager.terminate
334+
when 'switch'
335+
# Terminate the app
336+
Maze::Runner.run_command('ControlTarget.exe terminate')
337+
when 'browser'
338+
# WebGL - do nothing
339+
else
340+
raise "Platform #{platform} has not been considered"
341+
end
342+
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)