Skip to content

Commit 03b1fa4

Browse files
Add tests for controller restart behaviour. (#71)
1 parent 4db57a0 commit 03b1fa4

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

test/async/container/controller.rb

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,49 @@ def controller.setup(container)
8484
end
8585
end
8686

87+
with "#restart" do
88+
it "replaces the running container with a new one" do
89+
def controller.setup(container)
90+
container.spawn do |instance|
91+
instance.ready!
92+
sleep
93+
end
94+
end
95+
96+
controller.start
97+
first = controller.container
98+
99+
expect(first).not.to be_nil
100+
expect(controller).to be(:running?)
101+
102+
# A restart is a blue-green swap: a new container is created and the old one is stopped.
103+
controller.restart
104+
105+
expect(controller.container).not.to be_equal(first)
106+
expect(controller).to be(:running?)
107+
ensure
108+
controller.stop(false)
109+
end
110+
111+
it "starts a new container if not already running" do
112+
def controller.setup(container)
113+
container.spawn do |instance|
114+
instance.ready!
115+
sleep
116+
end
117+
end
118+
119+
expect(controller).not.to be(:running?)
120+
121+
controller.restart
122+
123+
expect(controller).to be(:running?)
124+
expect(controller.container).not.to be_nil
125+
ensure
126+
controller.stop(false)
127+
end
128+
end
129+
87130
with "notify" do
88131
before do
89132
@notify_server = Async::Container::Notify::Server.open

0 commit comments

Comments
 (0)