Sha256: fb26353ada358b8e2edbe496197ababc979c4fd25514625b766fdc0a60a7abaf

Contents?: true

Size: 1.74 KB

Versions: 2

Compression:

Stored size: 1.74 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

require 'drbqs/command_line/command_line'
require 'drbqs/task/task'
require 'drbqs/utility/temporary'

describe DRbQS::Server do
  def wait_file_creation(path)
    @max_wait_time.times do |i|
      if File.exist?(path)
        break
      end
      sleep(1)
    end
  end

  before(:all) do
    @file = DRbQS::Temporary.file
    @initial_data = ['abc', 'def']
    @max_wait_time = 10
    @server_process_id, @uri = drbqs_fork_server(14090, :opts => { :not_exit => true }) do |server|
      server.add_hook(:process_data) do |srv, data|
        open(@file, 'a+') do |f|
          f.print data
        end
      end
      server.set_data(*@initial_data)
    end
    @manage = DRbQS::Manage.new(:uri => @uri)
  end

  it "should process initial data." do
    wait_file_creation(@file)
    File.read(@file).should == 'abcdef'
  end

  it "should save to the file." do
    data = 'hello world'
    @manage.send_data(data)
    wait_file_creation(@file)
    File.read(@file).should == data
  end

  it "should send string by command." do
    data = 'send command'
    fork do
      DRbQS::Command::Manage.exec(['send', 'string', @uri, data])
    end
    wait_file_creation(@file)
    File.read(@file).should == data
  end

  it "should send file by command." do
    path = File.expand_path(__FILE__)
    fork do
      DRbQS::Command::Manage.exec(['send', 'file', @uri, path])
    end
    wait_file_creation(@file)
    File.read(@file).should == File.read(path)
  end

  after(:each) do
    FileUtils.rm(@file) if File.exist?(@file)
  end

  after(:all) do
    DRbQS::Temporary.delete
    @manage.send_exit_signal
    lambda do
      drbqs_wait_kill_server(@server_process_id)
    end.should_not raise_error
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
drbqs-0.1.1 spec/integration_test/09_server_process_data_spec.rb
drbqs-0.1.0 spec/integration_test/09_server_process_data_spec.rb