Module: PantryAcceptanceHelpers

Included in:
Minitest::Test
Defined in:
lib/pantry/test/acceptance.rb

Instance Method Summary collapse

Instance Method Details

#after_teardownObject



72
73
74
75
76
77
78
# File 'lib/pantry/test/acceptance.rb', line 72

def after_teardown
  @client1.shutdown if @client1
  @client2.shutdown if @client2
  @server.shutdown  if @server

  Celluloid.shutdown rescue nil
end

#configure_pantry(ports_start_at: 10101, heartbeat: 300, security: nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/pantry/test/acceptance.rb', line 34

def configure_pantry(ports_start_at: 10101, heartbeat: 300, security: nil)
  Pantry.config.server_host  = "127.0.0.1"
  Pantry.config.pub_sub_port = ports_start_at
  Pantry.config.receive_port = ports_start_at + 1
  Pantry.config.file_service_port = ports_start_at + 2
  Pantry.config.client_heartbeat_interval = heartbeat
  Pantry.config.response_timeout = 5
  Pantry.config.security = security

  begin
    Pantry.add_server_command(ServerEchoCommand)
  rescue Pantry::DuplicateCommandError
    # Already registered
  end
end

#set_up_environment(ports_start_at: 10101, heartbeat: 300, security: nil) ⇒ Object

Set up a fully functional Server + 2 Client environment on the given ports Make sure that the ports given are different for each test or port-conflict errors will happen. Tests should also have a wide enough range between their ports, to ensure there’s room for the current setup and any later expansion (10 is a good number).

This helper exposes @server, @client1, and @client2 for use in tests



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/pantry/test/acceptance.rb', line 56

def set_up_environment(ports_start_at: 10101, heartbeat: 300, security: nil)
  Celluloid.boot

  configure_pantry(ports_start_at: ports_start_at, heartbeat: heartbeat, security: security)

  @server = Pantry::Server.new
  @server.identity = "Test Server"
  @server.run

  @client1 = Pantry::Client.new identity: "client1", application: "pantry", environment: "test", roles: ["app1"]
  @client1.run

  @client2 = Pantry::Client.new identity: "client2", application: "pantry", environment: "test", roles: ["app2"]
  @client2.run
end