diff --git a/docker/docker-compose.test.yml b/docker/docker-compose.test.yml index a4ae69c6..c4aadc08 100644 --- a/docker/docker-compose.test.yml +++ b/docker/docker-compose.test.yml @@ -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: @@ -40,6 +41,8 @@ services: interval: 30s timeout: 10s retries: 5 + ports: + - 6379:6379 # redis-cache: # image: redis:${REDIS_VERSION:-7-alpine} diff --git a/test/api/v01/helpers/request_helper.rb b/test/api/v01/helpers/request_helper.rb index 267e9c10..a8f9585d 100644 --- a/test/api/v01/helpers/request_helper.rb +++ b/test/api/v01/helpers/request_helper.rb @@ -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