Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions docker/docker-compose.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ x-default-service: &default-service
OPTIM_DEFAULT_MAX_LATENESS_RATIO: 1
OPTIM_GENERATE_GEOJSON_POLYLINES: 'true'
# REDIS_CACHE_HOST: redis-cache
REDIS_RESQUE_HOST: redis-resque
REDIS_RESQUE_HOST: localhost
REDIS_RESULT_TTL_DAYS: ${REDIS_RESULT_TTL_DAYS:-1}
depends_on:
- redis-resque
redis-resque:
condition: service_healthy
# - redis-cache

services:
Expand Down Expand Up @@ -40,6 +41,8 @@ services:
interval: 30s
timeout: 10s
retries: 5
ports:
- 6379:6379

# redis-cache:
# image: redis:${REDIS_VERSION:-7-alpine}
Expand Down
32 changes: 1 addition & 31 deletions test/api/v01/helpers/request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,44 +150,14 @@ def delete_completed_job(job_id, params)
JSON.parse(last_response.body)
end

def asynchronously(options = {start_worker: false})
def asynchronously(_options = {start_worker: false})
old_config_solve_synchronously = OptimizerWrapper.config[:solve][:synchronously]
OptimizerWrapper.config[:solve][:synchronously] = false
old_resque_inline = Resque.inline
Resque.inline = false
if options[:start_worker] && !ENV['DOCKER']
pid_worker = Process.spawn({ 'COUNT' => '1', 'QUEUE' => 'DEFAULT' },
'bundle exec rake resque:workers --trace', pgroup: true) # don't create another shell
pgid_worker = Process.getpgid(pid_worker)
while `ps -o pgid | grep #{pgid_worker}`.split(/\n/).size < 2
puts "#{Time.now} Waiting for the worker to launch"
sleep 0.1
end
puts "#{Time.now} Worker is started"
sleep 0.1
end
yield
ensure
Resque.inline = old_resque_inline
OptimizerWrapper.config[:solve][:synchronously] = old_config_solve_synchronously
if options[:start_worker] && !ENV['DOCKER'] && pgid_worker
# Kill all grandchildren
worker_pids = `ps -o pgid,pid | grep #{pgid_worker}`.split(/\n/)
worker_pids.collect!{ |i| i.split(' ')[-1].to_i }
worker_pids.sort!
worker_pids.reverse_each{ |pid|
next if pid == pgid_worker

Process.kill('SIGKILL', pid)
Process.detach(pid)
}
Process.kill('SIGTERM', -pgid_worker) # Kill the process group (this doesn't kill grandchildren)
Process.waitpid(-pgid_worker, 0)
while `ps -o pgid,pid | grep "#{worker_pids.join('\|')}"`.split(/\n/).any?
puts "#{Time.now} Waiting the worker process group #{pgid_worker} to die\n"
sleep 0.1
end
puts "#{Time.now} Worker is killed"
end
end
end
Loading