Sha256: 036527a853b3609815cb650bfa51c5271b164fd48c407eb9d3a6b112a715b5e9

Contents?: true

Size: 1.68 KB

Versions: 4

Compression:

Stored size: 1.68 KB

Contents

require_relative '../spec_helper'

describe Sqewer::CLI, :sqs => true do
  describe 'runs the commandline app, executes jobs and then quits cleanly' do
    it 'on a USR1 signal' do
      submitter = Sqewer::Connection.default
    
      stderr = Tempfile.new('worker-stderr')
      stderr.sync = true
      
      pid = fork { $stderr.reopen(stderr); exec("ruby #{__dir__}/cli_app.rb") }
  
      Thread.new do
        20.times do
          j = {job_class: 'MyJob', first_name: 'John', last_name: 'Doe'}
          submitter.send_message(JSON.dump(j))
        end
      end
   
      sleep 8 # Give it some time to process all the jobs
      Process.kill("USR1", pid)
      sleep 2
      
      generated_files = Dir.glob('*-result')
      expect(generated_files).not_to be_empty
      generated_files.each{|path| File.unlink(path) }
    
      stderr.rewind
      log_output = stderr.read
      expect(log_output).to include('Stopping (clean shutdown)')
    end
    
    it 'on a TERM signal' do
      submitter = Sqewer::Connection.default
    
      stderr = Tempfile.new('worker-stderr')
      stderr.sync = true
    
      pid = fork { $stderr.reopen(stderr); exec("ruby #{__dir__}/cli_app.rb") }
  
      Thread.new do
        20.times do
          j = {job_class: 'MyJob', first_name: 'John', last_name: 'Doe'}
          submitter.send_message(JSON.dump(j))
        end
      end
   
      sleep 4
      Process.kill("TERM", pid)
    
      generated_files = Dir.glob('*-result')
      expect(generated_files).not_to be_empty
      generated_files.each{|path| File.unlink(path) }
    
      stderr.rewind
      log_output = stderr.read
      expect(log_output).to include('Stopping (clean shutdown)')
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sqewer-3.0.0 spec/sqewer/cli_spec.rb
sqewer-2.0.2 spec/sqewer/cli_spec.rb
sqewer-2.0.1 spec/sqewer/cli_spec.rb
sqewer-2.0.0 spec/sqewer/cli_spec.rb