Skip to content

Commit

Permalink
updated ClientComplete to do nothing if node is already complete
Browse files Browse the repository at this point in the history
  • Loading branch information
keithwiersema committed Oct 3, 2017
1 parent 821ad85 commit 8128a01
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/backbeat/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,14 @@ class ClientComplete < Event
scheduler Schedulers::PerformEvent

def call(node)
StateManager.new(node, response).with_rollback do |state|
state.transition(current_client_status: :complete, current_server_status: :processing_children)
node.mark_complete!
Server.fire_event(MarkChildrenReady, node)
if !node.complete?
StateManager.new(node, response).with_rollback do |state|
state.transition(current_client_status: :complete, current_server_status: :processing_children)
node.mark_complete!
Server.fire_event(MarkChildrenReady, node)
end
else
Logger.info(message: "Node already complete", node: node.id)
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/events_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,21 @@
expect(node.current_client_status).to eq("complete")
end

it "does nothing if the node is already complete" do
node.update_attributes(
current_client_status: :complete,
current_server_status: :complete
)

expect(Backbeat::Server).to_not receive(:fire_event).with(Backbeat::Events::MarkChildrenReady, node)
expect(node).to_not receive(:mark_complete!)

Backbeat::Events::ClientComplete.call(node)

expect(node.current_server_status).to eq("complete")
expect(node.current_client_status).to eq("complete")
end

it "rolls back if error occurs" do
expect(Backbeat::Server).to receive(:fire_event).with(Backbeat::Events::MarkChildrenReady, node).and_raise "error"
expect { Backbeat::Events::ClientComplete.call(node) }.to raise_error
Expand Down

0 comments on commit 8128a01

Please sign in to comment.