Class: Restate::Testing::RestateTestHarness

Inherits:
Object
  • Object
show all
Defined in:
lib/restate/testing.rb

Overview

Manages the lifecycle of an SDK server and a Restate container for testing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*services, restate_image: 'docker.io/restatedev/restate:latest', always_replay: false, disable_retries: false) {|Endpoint| ... } ⇒ RestateTestHarness

Returns a new instance of RestateTestHarness.

Parameters:

  • services (Array<Class>)

    Service classes to register.

  • restate_image (String) (defaults to: 'docker.io/restatedev/restate:latest')

    Docker image for Restate server.

  • always_replay (Boolean) (defaults to: false)

    Force replay on every suspension point.

  • disable_retries (Boolean) (defaults to: false)

    Disable Restate retry policy.

Yields:

  • (Endpoint)

    Optional block to configure the endpoint (e.g. add middleware).



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

def initialize(*services,
               restate_image: 'docker.io/restatedev/restate:latest',
               always_replay: false,
               disable_retries: false,
               &configure)
  @services = services
  @restate_image = restate_image
  @always_replay = always_replay
  @disable_retries = disable_retries
  @configure = configure
  @server_thread = nil
  @container = nil
  @port = nil
  @ingress_url = nil
  @admin_url = nil
end

Instance Attribute Details

#admin_urlObject (readonly)

Returns the value of attribute admin_url.



49
50
51
# File 'lib/restate/testing.rb', line 49

def admin_url
  @admin_url
end

#ingress_urlObject (readonly)

Returns the value of attribute ingress_url.



49
50
51
# File 'lib/restate/testing.rb', line 49

def ingress_url
  @ingress_url
end

Instance Method Details

#startObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/restate/testing.rb', line 73

def start
  @port = find_free_port
  endpoint = Restate.endpoint(*@services)
  @configure&.call(endpoint)
  rack_app = endpoint.app
  start_sdk_server(rack_app)
  wait_for_tcp(@port)
  start_restate_container
  register_sdk
  self
rescue StandardError => e
  stop
  raise e
end

#stopObject



88
89
90
91
# File 'lib/restate/testing.rb', line 88

def stop
  stop_restate_container
  stop_sdk_server
end