Sha256: 1716b3becc21742b04ae57466d227776cfad2d4d5b02df08ea5009d952e58efd

Contents?: true

Size: 931 Bytes

Versions: 35

Compression:

Stored size: 931 Bytes

Contents

class FakeClient
  def initialize
    @data = {}
    @uploaded = {}
    @uploads = 0
    @downloads = 0
    @mutex = Mutex.new
    @cond = ConditionVariable.new
    @go = false
  end

  attr_reader :uploaded, :uploads, :downloads
  attr_accessor :delay, :error

  def []=(key, value)
    @data[key] = value
  end

  def download
    wait_for_delay
    raise_error_if_present
    @downloads += 1
    yield @data.dup
    nil
  end

  def upload(data)
    wait_for_delay
    raise_error_if_present
    @uploaded.update(data)
    @uploads += 1
  end

  def uploaded?
    @uploads > 0
  end

  def downloaded?
    @downloads > 0
  end

  def go
    @mutex.synchronize do
      @go = true
      @cond.signal
    end
  end

  private

  def wait_for_delay
    if delay
      @mutex.synchronize do
        @cond.wait(@mutex) until @go
      end
    end
  end

  def raise_error_if_present
    if error
      raise error
    end
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
copy_tuner_client-0.19.0 spec/support/fake_client.rb
copy_tuner_client-0.18.0 spec/support/fake_client.rb
copy_tuner_client-0.17.1 spec/support/fake_client.rb
copy_tuner_client-0.16.3 spec/support/fake_client.rb
copy_tuner_client-0.16.2 spec/support/fake_client.rb
copy_tuner_client-0.16.1 spec/support/fake_client.rb
copy_tuner_client-0.16.0 spec/support/fake_client.rb
copy_tuner_client-0.15.1 spec/support/fake_client.rb
copy_tuner_client-0.15.0 spec/support/fake_client.rb
copy_tuner_client-0.14.2 spec/support/fake_client.rb
copy_tuner_client-0.14.1 spec/support/fake_client.rb
copy_tuner_client-0.14.0 spec/support/fake_client.rb
copy_tuner_client-0.13.6 spec/support/fake_client.rb
copy_tuner_client-0.13.5 spec/support/fake_client.rb
copy_tuner_client-0.13.3 spec/support/fake_client.rb
copy_tuner_client-0.13.2 spec/support/fake_client.rb
copy_tuner_client-0.13.1 spec/support/fake_client.rb
copy_tuner_client-0.13.0 spec/support/fake_client.rb
copy_tuner_client-0.12.0 spec/support/fake_client.rb
copy_tuner_client-0.11.0 spec/support/fake_client.rb