Sha256: 4ef8eb3afc4a36a31ad68f51a5dc0ee3f773f27cf74125b40669c0d7a2338e96

Contents?: true

Size: 1.88 KB

Versions: 17

Compression:

Stored size: 1.88 KB

Contents

# Allow test to be run in-place without requiring a gem install
$LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'

require 'rubygems'
require 'test/unit'
require 'shoulda'
require 'ruby_skynet'

# Register an appender if one is not already registered
SemanticLogger.default_level = :trace
SemanticLogger.add_appender('test.log') if SemanticLogger.appenders.size == 0

class TestService
  include RubySkynet::Service

  # Methods implemented by this service
  # Must take a Hash as input
  # Must Return a Hash response or nil for no response
  def echo(params)
    params
  end

  def exception_test(params)
    raise "Exception message"
  end
end

# Unit Test for ResilientSocket::TCPClient
class ServiceTest < Test::Unit::TestCase
  context 'RubySkynet::Service' do
    context "with server" do
      setup do
        @region = 'Test'
        @service_name = 'TestService'
        @version = 1
        RubySkynet.region = @region
        RubySkynet::Server.start
        sleep 0.2
      end

      teardown do
        RubySkynet::Server.stop
        SemanticLogger::Logger.flush
      end

      should "be running" do
        assert_equal true, RubySkynet::Server.running?
      end

      context "using a client" do
        setup do
          @client = RubySkynet::Client.new(@service_name, @version, @region)
        end

        should "successfully send and receive data" do
          reply = @client.call(:echo, 'some' => 'parameters')
          assert_equal 'some', reply.keys.first
          assert_equal 'parameters', reply.values.first
        end

        # Cellulloid 0.13.0.pre2 is doing something weird here and preventing the
        # Server from receiving the exception
        should "handle service exceptions" do
          reply = @client.call(:exception_test, 'some' => 'parameters')
          assert_equal "Exception message", reply['exception']['message']
        end
      end

    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ruby_skynet-1.3.0.alpha3 test/service_test.rb
ruby_skynet-1.3.0.alpha2 test/service_test.rb
ruby_skynet-1.3.0.alpha1 test/service_test.rb
ruby_skynet-1.2.7 test/service_test.rb
ruby_skynet-1.2.6 test/service_test.rb
ruby_skynet-1.2.5 test/service_test.rb
ruby_skynet-1.2.4 test/service_test.rb
ruby_skynet-1.2.3 test/service_test.rb
ruby_skynet-1.2.2 test/service_test.rb
ruby_skynet-1.2.1 test/service_test.rb
ruby_skynet-1.2.0 test/service_test.rb
ruby_skynet-1.1.1 test/service_test.rb
ruby_skynet-1.1.0 test/service_test.rb
ruby_skynet-1.0.0 test/service_test.rb
ruby_skynet-0.8.1 test/service_test.rb
ruby_skynet-0.8.0 test/service_test.rb
ruby_skynet-0.7.0 test/service_test.rb