Skip to content

Commit de5de74

Browse files
committed
Run jar test compatible with Windows
1 parent a73bdb8 commit de5de74

File tree

2 files changed

+94
-100
lines changed

2 files changed

+94
-100
lines changed

test/test_panorama_jar.rb

Lines changed: 94 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,108 @@
11
# Test the Panorama jar file
22
# Should be started in RAILS_ROOT directory
33

4-
# Raise error if file does not exist
5-
unless File.exist?('Panorama.jar')
6-
puts "Panorama.jar does not exist in #{Dir.pwd}"
7-
exit 1
4+
require 'open3'
5+
require 'net/http'
6+
require 'uri'
7+
8+
def log_output(stdout, stderr)
9+
puts "===== stdout of Panorama.jar ====="
10+
stdout.each_line do |line|
11+
puts line
12+
end
13+
puts "===== stderr of Panorama.jar ====="
14+
stderr.each_line do |line|
15+
puts line
16+
end
817
end
918

10-
# Start Panorama.jar in background
11-
system('java -jar Panorama.jar > panorama.log 2>&1 &')
19+
retcode = 0
20+
begin
1221

13-
puts "Waiting for InitializationJob to be performed"
14-
max_wait = 120
15-
loops = 0
22+
# Raise error if file does not exist
23+
unless File.exist?('Panorama.jar')
24+
raise "Panorama.jar does not exist in #{Dir.pwd}"
25+
end
1626

17-
while loops < max_wait
18-
retval = system('grep "Performed InitializationJob" panorama.log > /dev/null')
19-
break if retval
27+
# Ensure that envirnment does not contain any GEM_HOME or GEM_PATH etc.
28+
ENV.delete('BUNDLE_BIN_PATH')
29+
ENV.delete('BUNDLE_GEMFILE')
30+
ENV.delete('BUNDLER_SETUP')
31+
ENV.delete('BUNDLER_VERSION')
32+
ENV.delete('GEM_HOME')
33+
ENV.delete('GEM_PATH')
34+
ENV.delete('RUBYLIB')
35+
ENV.delete('RUBYOPT')
36+
# Start Panorama.jar in background
37+
stdin, stdout, stderr, thread = Open3.popen3(ENV, 'java -jar Panorama.jar')
2038

21-
loops += 1
22-
print '.'
23-
sleep 1
24-
end
39+
puts "Waiting for InitializationJob to be performed"
40+
max_wait = 60
41+
loops = 0
2542

26-
if loops == max_wait
27-
puts "InitializationJob not finished after #{max_wait} seconds"
28-
puts "===== log output from Panorama.jar ====="
29-
puts File.read('panorama.log')
30-
exit 1
31-
else
32-
puts "InitializationJob finished after #{loops} seconds"
33-
end
43+
break_outer = false
44+
while loops < max_wait
45+
if stdout.closed?
46+
puts "stdout closed"
47+
else
48+
stdout.each_line do |line|
49+
if line['Performed InitializationJob']
50+
break_outer = true
51+
break
52+
end
53+
end
54+
end
55+
break if break_outer
56+
loops += 1
57+
print '.'
58+
sleep 1
59+
end
3460

35-
loops = 0
36-
while loops < max_wait
37-
retval = system('curl http://localhost:8080/ > /dev/null 2> /dev/null')
38-
break if retval
61+
if loops == max_wait
62+
raise "InitializationJob not finished after #{max_wait} seconds"
63+
else
64+
puts "InitializationJob finished after #{loops} seconds"
65+
end
3966

40-
loops += 1
41-
print '.'
42-
sleep 1
43-
end
67+
response = nil
68+
puts "Waiting for access to port 8080 now"
69+
loops = 0
70+
while loops < max_wait
71+
uri = URI.parse('http://localhost:8080/')
72+
73+
begin
74+
response = Net::HTTP.get_response(uri)
75+
# Check if the response is successful (status code 200)
76+
break if response.is_a?(Net::HTTPSuccess)
77+
rescue SocketError, Errno::ECONNREFUSED, Net::OpenTimeout, Net::ReadTimeout => e
78+
end
4479

45-
if loops == max_wait
46-
puts "No access to port 8080 after #{max_wait} seconds"
47-
puts "===== log output from Panorama.jar ====="
48-
puts File.read('panorama.log')
49-
exit 1
50-
else
51-
puts "Access to port 8080 after #{loops} seconds"
80+
loops += 1
81+
print '.'
82+
sleep 1
83+
end
84+
85+
if loops == max_wait
86+
raise "No access to port 8080 after #{max_wait} seconds"
87+
else
88+
puts "Access to port 8080 after #{loops} seconds"
89+
end
90+
91+
# Check the content
92+
raise "Response should contain 'Please choose saved connection'" unless response.body['Please choose saved connection']
93+
94+
rescue Exception => e
95+
puts "Error: #{e.message}"
96+
retcode = 1
97+
ensure
98+
# Terminate the java process
99+
Process.kill('KILL', thread.pid)
100+
log_output(stdout, stderr)
101+
stdin.close
102+
stdout.close
103+
stderr.close
104+
puts "Test finished"
52105
end
53106

54-
# Check the content
107+
108+
exit retcode

test/test_panorama_jar.sh

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)