Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 121 lines (98 sloc) 3.062 kB
6fa4dea @jvatic Add Rakefile with db:migrate task
jvatic authored
1 require 'bundler/setup'
2 require 'bundler/gem_tasks'
3
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
4 task :validator_spec do
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
5 $stdout, $stderr = STDOUT.dup, STDERR.dup
6
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
7 # get random port
8 require 'socket'
9 tmp_socket = Socket.new(:INET, :STREAM)
10 tmp_socket.bind(Addrinfo.tcp("127.0.0.1", 0))
11 host, port = tmp_socket.local_address.getnameinfo
12 tmp_socket.close
13
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
14 def puts_error(e)
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
15 $stderr.print "#{e.inspect}:\n\t"
16 $stderr.puts e.backtrace.slice(0, 20).join("\n\t")
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
17 end
18
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
19 tentd_pid = fork do
20 require 'puma/cli'
21
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
22 STDOUT.reopen '/dev/null'
23 STDERR.reopen '/dev/null'
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
24
25 # don't show database activity
26 ENV['DB_LOGFILE'] ||= '/dev/null'
27
fec1cad @jvatic Fix: Assume host is localhost when running validator
jvatic authored
28 ENV['TENT_ENTITY'] ||= "http://localhost:#{port}#{ENV['TENT_SUBDIR']}"
00a37c5 @jvatic Set TENT_ENTITY in validator rake task
jvatic authored
29
d00014e @jvatic Setup travis
jvatic authored
30 # use test database
d9ca74f @jvatic Ensure TEST_DATABASE_URL given
jvatic authored
31 unless ENV['DATABASE_URL'] = ENV['TEST_DATABASE_URL']
c381814 @jvatic Remove debug
jvatic authored
32 STDERR.puts "You must set TEST_DATABASE_URL!"
d9ca74f @jvatic Ensure TEST_DATABASE_URL given
jvatic authored
33 exit 1
34 end
d00014e @jvatic Setup travis
jvatic authored
35
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
36 $stdout.puts "Booting Tent server on port #{port}..."
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
37
d391f0c @jvatic Add sidekiq
jvatic authored
38 ENV['RUN_SIDEKIQ'] = 'true' # Boot sidekiq server
39 ENV['SIDEKIQ_LOG'] = File.join(File.expand_path(File.dirname(__FILE__)), 'sidekiq.log')
40
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
41 rackup_path = File.expand_path(File.join(File.dirname(__FILE__), 'config.ru'))
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
42 cli = Puma::CLI.new ['--port', port.to_s, rackup_path]
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
43 begin
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
44 cli.run
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
45 rescue => e
46 puts_error(e)
47 exit 1
48 end
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
49 end
50
51 validator_pid = fork do
0c74274 @jvatic Update validator_spec rake task to handle validator sidekiq server
jvatic authored
52 validator_pid = Process.pid
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
53 at_exit do
0c74274 @jvatic Update validator_spec rake task to handle validator sidekiq server
jvatic authored
54 if Process.pid == validator_pid
55 $stdout.puts "Stopping Tent server (PID: #{tentd_pid})..."
56 begin
57 Process.kill("INT", tentd_pid)
58 rescue Errno::ESRCH
59 end
b2f7a30 @jvatic Swollow invalid pid errors when killing process
jvatic authored
60 end
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
61 end
62
0c74274 @jvatic Update validator_spec rake task to handle validator sidekiq server
jvatic authored
63 ENV['SIDEKIQ_LOG'] = File.join(File.expand_path(File.dirname(__FILE__)), 'validator-sidekiq.log')
64
fda8de3 @jvatic Fix: always use postgres to store attachments in validator
jvatic authored
65 # always use postgres for attachments
b97c68a @jvatic Add POSTGRES_ATTACHMENTS=true to force use of postgres when other sto…
jvatic authored
66 ENV['POSTGRES_ATTACHMENTS'] = 'true'
796fcc9 @jvatic Add support for S3 and local filesystem for attachment storage via fog
jvatic authored
67
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
68 # wait until tentd server boots
69 tentd_started = false
70 until tentd_started
71 begin
72 Socket.tcp("127.0.0.1", port) do |connection|
73 tentd_started = true
74 connection.close
75 end
76 rescue Errno::ECONNREFUSED
d8ab76a @jvatic Swollow Interupt error when waiting for tentd to start
jvatic authored
77 rescue Interrupt
78 exit
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
79 end
80 end
81
9635dcc @jvatic Setup TentValidator with server meta
jvatic authored
82 # don't show database activity
83 ENV['DB_LOGFILE'] ||= '/dev/null'
84
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
85 begin
86 require 'tent-validator'
fec1cad @jvatic Fix: Assume host is localhost when running validator
jvatic authored
87 server_url = "http://localhost:#{port}#{ENV['TENT_SUBDIR']}"
9635dcc @jvatic Setup TentValidator with server meta
jvatic authored
88 TentValidator.setup!(
89 :remote_entity_uri => server_url,
90 :tent_database_url => ENV['TEST_VALIDATOR_TEND_DATABASE_URL']
91 )
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
92 TentValidator::Runner::CLI.run
93 rescue => e
1ab8789 @jvatic Exit with status 1 when exception occurs
jvatic authored
94 puts_error(e)
95 exit 1
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
96 end
97 end
98
99 # wait for tentd process to exit
100 Process.waitpid(tentd_pid)
101
1ecfc3c @jvatic Fix exit status and don't print request log for validator_spec rake task
jvatic authored
102 if $?.exitstatus == 0
103 Process.waitpid(validator_pid)
104 else
105 # kill validator if tentd exits first with non-0 status
106 $stdout.puts "Stopping Validator (PID: #{validator_pid})..."
107 begin
108 Process.kill("INT", validator_pid)
109 rescue Errno::ESRCH
110 end
b2f7a30 @jvatic Swollow invalid pid errors when killing process
jvatic authored
111 end
e603ef9 @jvatic Propagate exit status
jvatic authored
112
113 exit $?.exitstatus
bc79003 @jvatic Add rake task to run tent-validator validations
jvatic authored
114 end
115
9f92637 @titanous Remove rspec references
titanous authored
116 task :default => :validator_spec
6fa4dea @jvatic Add Rakefile with db:migrate task
jvatic authored
117
118 lib = File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
119 $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
120 require 'tentd/tasks/db'
Something went wrong with that request. Please try again.