1414
1515WebMock . disable_net_connect! ( allow_localhost : true )
1616
17+ module TypesenseTestState
18+ @started_by_tests = false
19+
20+ def self . started_by_tests?
21+ @started_by_tests
22+ end
23+
24+ def self . mark_started
25+ @started_by_tests = true
26+ end
27+ end
28+
1729def typesense_healthy? ( host = 'localhost' , port = 8108 )
1830 conn = Faraday . new ( "http://#{ host } :#{ port } " )
1931 response = conn . get ( '/health' )
@@ -29,14 +41,10 @@ def start_typesense_if_needed
2941 end
3042
3143 # Check if Docker is running
32- unless system ( 'docker info > /dev/null 2>&1' )
33- raise 'Docker daemon is not running. Please start Docker and try again.'
34- end
44+ raise 'Docker daemon is not running. Please start Docker and try again.' unless system ( 'docker info > /dev/null 2>&1' )
3545
3646 puts 'Starting Typesense with docker-compose...'
37- unless system ( 'docker-compose up -d' )
38- raise 'Failed to start docker-compose'
39- end
47+ raise 'Failed to start docker-compose' unless system ( 'docker-compose up -d' )
4048
4149 # Wait for Typesense to be ready
4250 print 'Waiting for Typesense to start'
@@ -48,17 +56,15 @@ def start_typesense_if_needed
4856 end
4957 puts
5058
51- unless typesense_healthy?
52- raise 'Failed to start Typesense - health endpoint did not return OK'
53- end
59+ raise 'Failed to start Typesense - health endpoint did not return OK' unless typesense_healthy?
5460
5561 puts 'Typesense is ready!'
56- $typesense_started_by_tests = true
62+ TypesenseTestState . mark_started
5763 true
5864end
5965
6066def stop_typesense_if_started
61- unless $typesense_started_by_tests
67+ unless TypesenseTestState . started_by_tests?
6268 puts "\e [33m\n Test suite did not shut down Typesense automatically, because it was already running when tests started\e [0m"
6369 return
6470 end
@@ -89,7 +95,7 @@ def stop_typesense_if_started
8995 config . shared_context_metadata_behavior = :apply_to_host_groups
9096
9197 config . before ( :suite ) do
92- $typesense_started_by_tests = start_typesense_if_needed
98+ start_typesense_if_needed
9399 WebMock . disable_net_connect!
94100 end
95101
0 commit comments