-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #643 from bugsnag/idempotent-previous-uuid
Allow the command server to provide the next ID when given the last from the previous scenario
- Loading branch information
Showing
14 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
ARG BRANCH_NAME | ||
ARG RUBY_VERSION | ||
FROM 855461928731.dkr.ecr.us-west-1.amazonaws.com/maze-runner:${BRANCH_NAME}-ci-ruby-${RUBY_VERSION} | ||
|
||
COPY . /app | ||
WORKDIR /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
source "https://rubygems.org" | ||
|
||
gem 'bugsnag-maze-runner', path: '../../..' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
Feature: Tests the command servlet works as expected | ||
|
||
Scenario: Commands are received in order | ||
Given I add a command with message "first" | ||
And I add a command with message "second" | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "first" | ||
And the error payload field "command_response.uuid" is stored as the value "uuid" | ||
And the error payload field "command_response.run_uuid" is stored as the value "run_uuid" | ||
And I discard the oldest error | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "second" | ||
And the error payload field "command_response.uuid" does not equal the stored value "uuid" | ||
And the error payload field "command_response.run_uuid" equals the stored value "run_uuid" | ||
|
||
Scenario: Idempotent commands are sent correctly | ||
Given I generate a series of commands with sequential UUIDs | ||
Then I run the "bounce_idempotent_command" test script with UUID "1" | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "second" | ||
And the error payload field "command_response.uuid" equals "2" | ||
And I discard the oldest error | ||
Then I run the "bounce_idempotent_command" test script with UUID "2" | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "third" | ||
And the error payload field "command_response.uuid" equals "3" | ||
And I discard the oldest error | ||
Then I run the "bounce_idempotent_command" test script with UUID "1" | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "second" | ||
And the error payload field "command_response.uuid" equals "2" | ||
|
||
Scenario: A noop is sent when no commands are added | ||
When I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "No commands queued" | ||
And the error payload field "command_response.action" equals "noop" | ||
And the error payload field "command_status" equals 200 | ||
|
||
Scenario: An noop is sent when commands run out | ||
Given I add a command with message "first" | ||
And I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "first" | ||
And I discard the oldest error | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "No commands queued" | ||
And the error payload field "command_response.action" equals "noop" | ||
And the error payload field "command_status" equals 200 | ||
|
||
Scenario: An error is sent when the idempotent UUID is incorrect | ||
Given I generate a series of commands with sequential UUIDs | ||
Then I run the "bounce_idempotent_command" test script with UUID "8" | ||
And I wait to receive an error | ||
Then the error payload field "command_response" equals "Request invalid - there is no command with a UUID of 8 to follow on from" | ||
And the error payload field "command_status" equals 400 | ||
|
||
Scenario: The next command is sent when the previous idempotent UUID is used | ||
Given I generate a series of commands with sequential UUIDs | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "first" | ||
And the error payload field "command_response.uuid" equals "1" | ||
And I discard the oldest error | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "second" | ||
And the error payload field "command_response.uuid" equals "2" | ||
And I discard the oldest error | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "third" | ||
And the error payload field "command_response.uuid" equals "3" | ||
And I discard the oldest error | ||
Then I run the "bounce_command" test script | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "fourth" | ||
And the error payload field "command_response.uuid" equals "4" | ||
And I discard the oldest error | ||
|
||
Then I add a command with message "fifth" | ||
And I run the "bounce_idempotent_command" test script with UUID "4" | ||
And I wait to receive an error | ||
Then the error payload field "command_response.message" equals "fifth" |
18 changes: 18 additions & 0 deletions
18
test/fixtures/command-workflow/features/scripts/bounce_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'date' | ||
require 'net/http' | ||
|
||
http = Net::HTTP.new('localhost', '9339') | ||
command_request = Net::HTTP::Get.new('/command') | ||
|
||
command_response = http.request(command_request) | ||
|
||
bounce_request = Net::HTTP::Post.new('/notify') | ||
bounce_request['Content-Type'] = 'application/json' | ||
bounce_request.body = %({ | ||
"command_response": #{command_response.body}, | ||
"command_status": #{command_response.code} | ||
}) | ||
|
||
http.request(bounce_request) |
30 changes: 30 additions & 0 deletions
30
test/fixtures/command-workflow/features/scripts/bounce_idempotent_command.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'date' | ||
require 'net/http' | ||
require 'json' | ||
|
||
target_uuid = ENV['COMMAND_UUID'] | ||
|
||
http = Net::HTTP.new('localhost', '9339') | ||
command_request = Net::HTTP::Get.new("/command?after=#{target_uuid}") | ||
|
||
command_response = http.request(command_request) | ||
|
||
bounce_request = Net::HTTP::Post.new('/notify') | ||
bounce_request['Content-Type'] = 'application/json' | ||
|
||
begin | ||
JSON.parse(command_response.body) | ||
bounce_request.body = %({ | ||
"command_response": #{command_response.body}, | ||
"command_status": #{command_response.code} | ||
}) | ||
rescue | ||
bounce_request.body = %({ | ||
"command_response": "#{command_response.body}", | ||
"command_status": #{command_response.code} | ||
}) | ||
end | ||
|
||
http.request(bounce_request) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
When('I add a command with message {string}') do |message| | ||
command = { | ||
message: message | ||
} | ||
Maze::Server.commands.add command | ||
end | ||
|
||
When('I generate a series of commands with sequential UUIDs') do | ||
Maze::Server.commands.add({ message: 'first'}) | ||
Maze::Server.commands.get(0)[:uuid] = '1' | ||
Maze::Server.commands.add({ message: 'second'}) | ||
Maze::Server.commands.get(1)[:uuid] = '2' | ||
Maze::Server.commands.add({ message: 'third'}) | ||
Maze::Server.commands.get(2)[:uuid] = '3' | ||
Maze::Server.commands.add({ message: 'fourth'}) | ||
Maze::Server.commands.get(3)[:uuid] = '4' | ||
end | ||
|
||
When('I run the {string} test script') do |test_script| | ||
steps %Q{ | ||
And I run the script "features/scripts/#{test_script}.rb" using ruby synchronously | ||
} | ||
end | ||
|
||
When('I run the {string} test script with UUID {string}') do |test_script, uuid| | ||
steps %Q{ | ||
When I set environment variable "COMMAND_UUID" to "#{uuid}" | ||
And I run the script "features/scripts/#{test_script}.rb" using ruby synchronously | ||
} | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Maze.config.enable_bugsnag = false | ||
|
||
BeforeAll do | ||
Maze.config.enforce_bugsnag_integrity = false | ||
end |