hermes_messenger_of_the_gods 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.drone.yml +9 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +13 -0
- data/README.md +464 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/fly_hermes +57 -0
- data/hermes_messenger_of_the_gods.gemspec +38 -0
- data/lib/hermes_messenger_of_the_gods.rb +57 -0
- data/lib/hermes_messenger_of_the_gods/concerns/base.rb +42 -0
- data/lib/hermes_messenger_of_the_gods/concerns/grpc_protobuf.rb +62 -0
- data/lib/hermes_messenger_of_the_gods/concerns/message.rb +194 -0
- data/lib/hermes_messenger_of_the_gods/concerns/mono_message.rb +52 -0
- data/lib/hermes_messenger_of_the_gods/concerns/worker.rb +173 -0
- data/lib/hermes_messenger_of_the_gods/configuration.rb +29 -0
- data/lib/hermes_messenger_of_the_gods/endpoint_builder.rb +41 -0
- data/lib/hermes_messenger_of_the_gods/endpoints.rb +3 -0
- data/lib/hermes_messenger_of_the_gods/endpoints/base.rb +113 -0
- data/lib/hermes_messenger_of_the_gods/endpoints/sns.rb +21 -0
- data/lib/hermes_messenger_of_the_gods/endpoints/sqs.rb +114 -0
- data/lib/hermes_messenger_of_the_gods/exceptions.rb +27 -0
- data/lib/hermes_messenger_of_the_gods/logging_helpers.rb +30 -0
- data/lib/hermes_messenger_of_the_gods/output/basic.rb +63 -0
- data/lib/hermes_messenger_of_the_gods/status_server.rb +48 -0
- data/lib/hermes_messenger_of_the_gods/testing/array_endpoint.rb +46 -0
- data/lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb +52 -0
- data/lib/hermes_messenger_of_the_gods/testing/rspec_helpers.rb +64 -0
- data/lib/hermes_messenger_of_the_gods/version.rb +3 -0
- data/packageGems.sh +13 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.bundlecache +0 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.circleci/config.yml +32 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.gitignore +11 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.rspec +3 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.rubocop.yml +42 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.ruby-version +1 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/.travis.yml +5 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/Gemfile +6 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/Gemfile.lock +75 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/Makefile +1 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/README.md +78 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/Rakefile +6 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/bundle +105 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/coderay +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/console +14 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/grpc_tools_ruby_protoc +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/grpc_tools_ruby_protoc_plugin +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/htmldiff +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/ldiff +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/pry +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/rake +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/rspec +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/rubocop +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/ruby-parse +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/ruby-rewrite +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/bin/setup +8 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/lib/protobuf3_fixer.rb +123 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/lib/protobuf3_fixer/encoder.rb +63 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/lib/protobuf3_fixer/generation_helpers.rb +23 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/lib/protobuf3_fixer/reflector.rb +66 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/lib/protobuf3_fixer/version.rb +3 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/protobuf3_fixer.gemspec +54 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/bundle +105 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/coderay +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/grpc_tools_ruby_protoc +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/grpc_tools_ruby_protoc_plugin +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/htmldiff +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/ldiff +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/pry +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/rake +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/rspec +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/rubocop +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/ruby-parse +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/rubocop/ruby-rewrite +29 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/build_from_hash_spec.rb +20 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/encoding/encoding_options_spec.rb +23 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/extra_fields/json_decode_of_superset_spec.rb +54 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/generation_helpers_spec.rb +37 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/protobuf3_fixer_spec.rb +5 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/spec_helper.rb +17 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/support/compiled_protobuffs/source/superset_pb.rb +44 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/support/compiled_protobuffs/source/timestamp_pb.rb +27 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/support/protobuffs/source/superset.proto +40 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/support/protobuffs/source/timestamp.proto +18 -0
- data/vendor/cache/Protobuf3Fixer-5f9f1a2d2da9/spec/well_known_type_fixes/timestamp_spec.rb +79 -0
- data/vendor/cache/activemodel-6.0.3.1.gem +0 -0
- data/vendor/cache/activesupport-6.0.3.1.gem +0 -0
- data/vendor/cache/addressable-2.6.0.gem +0 -0
- data/vendor/cache/aws-eventstream-1.1.0.gem +0 -0
- data/vendor/cache/aws-partitions-1.329.0.gem +0 -0
- data/vendor/cache/aws-sdk-core-3.99.2.gem +0 -0
- data/vendor/cache/aws-sdk-sns-1.25.1.gem +0 -0
- data/vendor/cache/aws-sdk-sqs-1.27.1.gem +0 -0
- data/vendor/cache/aws-sigv4-1.1.4.gem +0 -0
- data/vendor/cache/codeclimate-test-reporter-1.0.9.gem +0 -0
- data/vendor/cache/coderay-1.1.2.gem +0 -0
- data/vendor/cache/concurrent-ruby-1.1.6.gem +0 -0
- data/vendor/cache/crack-0.4.3.gem +0 -0
- data/vendor/cache/diff-lcs-1.3.gem +0 -0
- data/vendor/cache/docile-1.1.5.gem +0 -0
- data/vendor/cache/google-protobuf-3.12.2-universal-darwin.gem +0 -0
- data/vendor/cache/google-protobuf-3.12.2-x86_64-linux.gem +0 -0
- data/vendor/cache/google-protobuf-3.12.2.gem +0 -0
- data/vendor/cache/googleapis-common-protos-types-1.0.2.gem +0 -0
- data/vendor/cache/grpc-1.18.0-universal-darwin.gem +0 -0
- data/vendor/cache/grpc-1.18.0-x86_64-linux.gem +0 -0
- data/vendor/cache/grpc-1.18.0.gem +0 -0
- data/vendor/cache/hashdiff-0.3.8.gem +0 -0
- data/vendor/cache/i18n-1.8.3.gem +0 -0
- data/vendor/cache/jmespath-1.4.0.gem +0 -0
- data/vendor/cache/json-2.1.0.gem +0 -0
- data/vendor/cache/memory_profiler-0.9.12.gem +0 -0
- data/vendor/cache/method_source-0.9.2.gem +0 -0
- data/vendor/cache/minitest-5.14.1.gem +0 -0
- data/vendor/cache/pry-0.12.2.gem +0 -0
- data/vendor/cache/public_suffix-3.0.3.gem +0 -0
- data/vendor/cache/rake-10.5.0.gem +0 -0
- data/vendor/cache/rspec-3.8.0.gem +0 -0
- data/vendor/cache/rspec-core-3.8.0.gem +0 -0
- data/vendor/cache/rspec-expectations-3.8.2.gem +0 -0
- data/vendor/cache/rspec-mocks-3.8.0.gem +0 -0
- data/vendor/cache/rspec-support-3.8.0.gem +0 -0
- data/vendor/cache/safe_yaml-1.0.4.gem +0 -0
- data/vendor/cache/simplecov-0.13.0.gem +0 -0
- data/vendor/cache/simplecov-html-0.10.2.gem +0 -0
- data/vendor/cache/thor-1.0.1.gem +0 -0
- data/vendor/cache/thread_safe-0.3.6.gem +0 -0
- data/vendor/cache/timecop-0.9.1.gem +0 -0
- data/vendor/cache/tzinfo-1.2.7.gem +0 -0
- data/vendor/cache/webmock-3.5.1.gem +0 -0
- data/vendor/cache/zeitwerk-2.3.0.gem +0 -0
- metadata +362 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HermesMessengerOfTheGods
|
4
|
+
if defined?(ActiveModel::ValidationError)
|
5
|
+
class ValidationError < ActiveModel::ValidationError; end
|
6
|
+
else
|
7
|
+
class ValidationError < StandardError
|
8
|
+
attr_reader :model
|
9
|
+
|
10
|
+
def initialize(model)
|
11
|
+
@model = model
|
12
|
+
errors = @model.errors.full_messages.join(', ')
|
13
|
+
super(errors)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
class MessageDispatchFailed < StandardError
|
19
|
+
attr_accessor :exceptions
|
20
|
+
end
|
21
|
+
class MessageDispatchTotalFailure < MessageDispatchFailed; end
|
22
|
+
class MessageDispatchPartialFailure < MessageDispatchFailed; end
|
23
|
+
|
24
|
+
module Endpoints
|
25
|
+
class FatalError < RuntimeError; end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
module HermesMessengerOfTheGods
|
4
|
+
module LoggingHelpers
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
included do
|
8
|
+
Logger::Severity.constants.each do |sev|
|
9
|
+
define_method(sev.downcase) do |msg = nil, &blk|
|
10
|
+
say("Logger::#{sev}".constantize, msg, &blk)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def say(level, msg = nil, &blk)
|
15
|
+
return if HermesMessengerOfTheGods.config.quiet
|
16
|
+
|
17
|
+
[*HermesMessengerOfTheGods.config.logger].compact.each do |logger|
|
18
|
+
logger.progname = logger.progname.tap do |_|
|
19
|
+
logger.progname = log_message_prefix
|
20
|
+
logger.log(level, msg, &blk)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def log_message_prefix
|
26
|
+
self.class.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Worker Output
|
2
|
+
module HermesMessengerOfTheGods
|
3
|
+
module Output
|
4
|
+
module Basic
|
5
|
+
@subscriptions = []
|
6
|
+
|
7
|
+
def self.unsubscribe!
|
8
|
+
@subscriptions.map{|s|ActiveSupport::Notifications.unsubscribe(s) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.subscribe!
|
12
|
+
unsubscribe!
|
13
|
+
|
14
|
+
@subscriptions = [
|
15
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.starting') do |*_, payload|
|
16
|
+
payload[:worker].info { "Starting Worker" }
|
17
|
+
end,
|
18
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.run_job') do |_, start, finish, _, payload|
|
19
|
+
payload[:worker].debug { "Completed #{to_log_s(payload[:job])} in #{finish - start}s" }
|
20
|
+
end,
|
21
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.starting_job') do |*_, payload|
|
22
|
+
payload[:worker].info { "Starting Job #{to_log_s(payload[:job])}" }
|
23
|
+
end,
|
24
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.success') do |*_, payload|
|
25
|
+
payload[:worker].info { "Finished Job #{to_log_s(payload[:job])}" }
|
26
|
+
end,
|
27
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.failure') do |*_, payload|
|
28
|
+
payload[:worker].error { "Error in #{to_log_s(payload[:job])}: #{payload[:error].message}" }
|
29
|
+
payload[:worker].debug { "backtrace: #{payload[:error].backtrace}" }
|
30
|
+
end,
|
31
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.worker.fatal_error') do |*_, payload|
|
32
|
+
payload[:worker].error { "Fatal Error: #{to_log_s(payload[:job])}: #{payload[:exception].message}" }
|
33
|
+
payload[:worker].debug { "backtrace: #{payload[:exception].backtrace}" }
|
34
|
+
end,
|
35
|
+
# Message Output
|
36
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.message.dispatch') do |_, _start, _finish, _, payload|
|
37
|
+
payload[:message].info { "Dispatch complete in #{to_log_s(payload[:job])}s" }
|
38
|
+
end,
|
39
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.message.dispatch_failure') do |*_, payload|
|
40
|
+
payload[:message].debug { "Dispatch failure to #{to_log_s(payload[:job])}: #{payload[:exception].inspect}" }
|
41
|
+
end,
|
42
|
+
# Endpoint Output
|
43
|
+
ActiveSupport::Notifications.subscribe('hermes_messenger_of_the_gods.endpoint.dispatch') do |_, start, finish, _, payload|
|
44
|
+
payload[:endpoint].info { "Dispatch complete in #{finish - start}s #{" FAILED" if payload.has_key?(:exception)}" }
|
45
|
+
end,
|
46
|
+
ActiveSupport::Notifications.subscribe(/hermes_messenger_of_the_gods.endpoint.(dispatch|final)_failure/) do |name, *_, payload|
|
47
|
+
payload[:endpoint].debug { "Dispatch #{"final " if name.include?('final_')} failure ##{payload[:try]} to #{payload[:endpoint_name]}: #{payload[:exception].inspect}" }
|
48
|
+
end,
|
49
|
+
ActiveSupport::Notifications.subscribe(/hermes_messenger_of_the_gods.endpoint.read_failure/) do |name, *_, payload|
|
50
|
+
payload[:endpoint].error { "A message was received that could not be decoded: #{payload[:exception].message}" }
|
51
|
+
end,
|
52
|
+
]
|
53
|
+
end
|
54
|
+
subscribe!
|
55
|
+
|
56
|
+
def self.to_log_s(item)
|
57
|
+
item.respond_to?(:to_log_s) ?
|
58
|
+
item.to_log_s :
|
59
|
+
item.inspect
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
module HermesMessengerOfTheGods
|
6
|
+
class WorkerStatusServer
|
7
|
+
def self.start!(worker:, port: nil)
|
8
|
+
new(worker: worker, port: port).start!
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :worker, :port
|
12
|
+
def initialize(worker:, port: nil)
|
13
|
+
self.worker = worker
|
14
|
+
self.port = port || ENV.fetch('HERMES_WORKER_STATUS_PORT', 4242).to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def start!
|
18
|
+
Thread.new do
|
19
|
+
server = TCPServer.open port
|
20
|
+
loop do
|
21
|
+
client = server.accept
|
22
|
+
client.puts construct_response
|
23
|
+
client&.close
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def construct_response
|
29
|
+
if worker.healthy?
|
30
|
+
resp = 'OKAY'
|
31
|
+
status_code = '200 OK'
|
32
|
+
else
|
33
|
+
resp = 'ERROR'
|
34
|
+
status_code = '500 Internal Server Error'
|
35
|
+
end
|
36
|
+
|
37
|
+
<<~RESPONSE
|
38
|
+
HTTP/1.1 #{status_code}
|
39
|
+
Date: #{Time.now.utc.strftime('%a, %d %b %Y %T GMT')}
|
40
|
+
Server: Ruby
|
41
|
+
Content-Type: text/html; charset=iso-8859-1
|
42
|
+
Content-Length: #{resp.length}
|
43
|
+
|
44
|
+
#{resp}
|
45
|
+
RESPONSE
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module HermesMessengerOfTheGods
|
4
|
+
module Endpoints
|
5
|
+
class Local < Base
|
6
|
+
class << self
|
7
|
+
attr_accessor :transmit_method
|
8
|
+
|
9
|
+
def clear_queue!
|
10
|
+
@received = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def received
|
14
|
+
@received ||= Hash.new { |h, k| h[k] = [] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def received
|
19
|
+
self.class.received[endpoint]
|
20
|
+
end
|
21
|
+
|
22
|
+
def transmit(msg, raw_msg, opts = {})
|
23
|
+
if self.class.transmit_method
|
24
|
+
self.class.transmit_method.call(self, msg, raw_msg)
|
25
|
+
else
|
26
|
+
do_transmit(msg, opts, raw_msg)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def do_transmit(msg, opts, raw_message = {})
|
31
|
+
pub_opts = fetch_option(:publish_options, raw_message) || {}
|
32
|
+
received << { message: msg, options: opts.merge(pub_opts) }
|
33
|
+
"Recorded msg ##{self.class.received[endpoint].length} for #{endpoint}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
if defined?(RSpec)
|
40
|
+
RSpec.configure do |config|
|
41
|
+
config.after(:each) do
|
42
|
+
HermesMessengerOfTheGods::Endpoints::Local.clear_queue!
|
43
|
+
HermesMessengerOfTheGods::Endpoints::Local.transmit_method = nil
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'rspec/expectations'
|
4
|
+
|
5
|
+
RSpec::Matchers.define :dispatch do |message|
|
6
|
+
supports_block_expectations
|
7
|
+
|
8
|
+
match do |proc|
|
9
|
+
@matched_early = @endpoint.received.detect do |m|
|
10
|
+
a_hash_including(message).matches?(m[:message]) && (
|
11
|
+
@options.nil? ||
|
12
|
+
a_hash_including(@options).matches?(m[:options])
|
13
|
+
) && (
|
14
|
+
@message_attributes.nil? || a_hash_including(@message_attributes).matches?(m[:message_attributes])
|
15
|
+
)
|
16
|
+
end
|
17
|
+
return false if @matched_early
|
18
|
+
|
19
|
+
proc.call
|
20
|
+
wait_for_async_dispatches
|
21
|
+
|
22
|
+
!!@endpoint.received.detect do |m|
|
23
|
+
a_hash_including(message).matches?(m[:message]) && (
|
24
|
+
@options.nil? ||
|
25
|
+
a_hash_including(@options).matches?(m[:options])
|
26
|
+
) && (
|
27
|
+
@message_attributes.nil? || a_hash_including(@message_attributes).matches?(m[:options][:message_attributes])
|
28
|
+
)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
chain :to_endpoint do |ep|
|
33
|
+
@endpoint = ep
|
34
|
+
end
|
35
|
+
|
36
|
+
chain :with_options do |options|
|
37
|
+
@options = options
|
38
|
+
end
|
39
|
+
|
40
|
+
chain :with_message_attributes do |attributes|
|
41
|
+
@message_attributes = attributes
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
failure_message do |_actual|
|
46
|
+
if @matched_early
|
47
|
+
"endpoint already received message that matched: #{message} - message that matched: #{@matched_early}"
|
48
|
+
else
|
49
|
+
"endpoint did not receive a message with content: #{message} - endpoint messages: #{@endpoint.received}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'hermes_messenger_of_the_gods/testing/array_endpoint'
|
4
|
+
require 'timeout'
|
5
|
+
|
6
|
+
module HermesMessengerOfTheGods
|
7
|
+
module Testing
|
8
|
+
module RSpecHelpers
|
9
|
+
def mock_endpoints
|
10
|
+
@mock_endpoints ||= Hash.new { |h, k| h[k] = {} }
|
11
|
+
end
|
12
|
+
|
13
|
+
def reset_all_mock_endpoints
|
14
|
+
mock_endpoints.values.map(&:values).flatten.map(&:teardown)
|
15
|
+
@mock_endpoints = nil
|
16
|
+
end
|
17
|
+
|
18
|
+
def fake_endpoint(type, endpoint, *args)
|
19
|
+
klass = "HermesMessengerOfTheGods::Endpoints::#{type.to_s.camelize}".constantize
|
20
|
+
|
21
|
+
build_fake_endpoint(klass, endpoint, *args).tap do |build_ep|
|
22
|
+
allow(HermesMessengerOfTheGods::EndpointBuilder).to receive(:build)
|
23
|
+
.with(anything, klass, endpoint, any_args).and_return(build_ep)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def build_fake_endpoint(klass, endpoint, *args)
|
28
|
+
endpoint = endpoint.to_s
|
29
|
+
raise "Endpoint required" if endpoint == ''
|
30
|
+
mock_endpoints[klass][endpoint].options.merge!(*args) if mock_endpoints[klass][endpoint]
|
31
|
+
mock_endpoints[klass][endpoint] ||= Endpoints::Local.new(endpoint, "#{klass}::#{endpoint}", *args)
|
32
|
+
mock_endpoints[klass][endpoint]
|
33
|
+
end
|
34
|
+
|
35
|
+
def setup_for_fake_endpoints!
|
36
|
+
allow(HermesMessengerOfTheGods::EndpointBuilder).to receive(:build)
|
37
|
+
.and_call_original
|
38
|
+
end
|
39
|
+
|
40
|
+
def fake_all_endpoints!
|
41
|
+
allow(HermesMessengerOfTheGods::EndpointBuilder).to receive(:build) do |_, klass, endpoint, *args|
|
42
|
+
build_fake_endpoint(klass, endpoint, *args)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def wait_for_async_dispatches
|
47
|
+
return if HermesMessengerOfTheGods.async_dispatches_in_progress.zero?
|
48
|
+
|
49
|
+
Timeout.timeout(5) do
|
50
|
+
sleep 0.01 until HermesMessengerOfTheGods.async_dispatches_in_progress.zero?
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if defined?(RSpec)
|
58
|
+
RSpec.configure do |config|
|
59
|
+
config.before(:each) do
|
60
|
+
setup_for_fake_endpoints!
|
61
|
+
reset_all_mock_endpoints
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/packageGems.sh
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
docker run --rm -t -i \
|
4
|
+
-v $HOME/.ssh:/root/.ssh \
|
5
|
+
--mount type=bind,source="$(pwd)",target=/app \
|
6
|
+
--workdir=/app/api \
|
7
|
+
getterminus/ruby-docker-images:2.6-je-20190204 \
|
8
|
+
/bin/bash -c "
|
9
|
+
bundle config specific_platform true && \
|
10
|
+
bundle lock --add-platform x86_64-linux && \
|
11
|
+
bundle lock --add-platform x86_64-darwin-18 && \
|
12
|
+
bundle package --all
|
13
|
+
"
|
File without changes
|
@@ -0,0 +1,32 @@
|
|
1
|
+
version: 2 # use CircleCI 2.0
|
2
|
+
jobs: # a collection of steps
|
3
|
+
build: # runs not using Workflows must have a `build` job as entry point
|
4
|
+
docker: # run the steps with Docker
|
5
|
+
- image: getterminus/ruby-ci-image:2.6-je-20190205 # ...with this image as the primary container; this is where all `steps` will run
|
6
|
+
environment: # environment variables for primary container
|
7
|
+
BUNDLE_JOBS: 3
|
8
|
+
BUNDLE_RETRY: 3
|
9
|
+
BUNDLE_PATH: vendor/bundle
|
10
|
+
steps: # a collection of executable commands
|
11
|
+
- checkout # special step to check out source code to working directory
|
12
|
+
|
13
|
+
# Restore bundle cache
|
14
|
+
- restore_cache:
|
15
|
+
keys:
|
16
|
+
- bundle-v2-{{ checksum "Gemfile.lock" }}
|
17
|
+
- bundle-v2-
|
18
|
+
|
19
|
+
- run:
|
20
|
+
name: Bundle Install
|
21
|
+
command: bundle check || bundle install
|
22
|
+
|
23
|
+
# Store bundle cache
|
24
|
+
- save_cache:
|
25
|
+
key: bundle-v2-{{ checksum "Gemfile.lock" }}
|
26
|
+
paths:
|
27
|
+
- vendor/bundle
|
28
|
+
|
29
|
+
- run:
|
30
|
+
name: Run rspec
|
31
|
+
command: |
|
32
|
+
bundle exec rspec --profile 10 --format progress
|
@@ -0,0 +1,42 @@
|
|
1
|
+
Style/Documentation:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/FrozenStringLiteralComment:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: always
|
7
|
+
|
8
|
+
Style/TrailingCommaInHashLiteral:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyleForMultiline: comma
|
11
|
+
|
12
|
+
Style/TrailingCommaInArrayLiteral:
|
13
|
+
Enabled: true
|
14
|
+
EnforcedStyleForMultiline: comma
|
15
|
+
|
16
|
+
Layout/EndAlignment:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Lint/UnusedMethodArgument:
|
20
|
+
AllowUnusedKeywordArguments: true
|
21
|
+
|
22
|
+
Metrics/LineLength:
|
23
|
+
Enabled: true
|
24
|
+
IgnoredPatterns: ['\A#']
|
25
|
+
Max: 120
|
26
|
+
|
27
|
+
Layout/AlignParameters:
|
28
|
+
Enabled: true
|
29
|
+
|
30
|
+
Naming/UncommunicativeMethodParamName:
|
31
|
+
Enabled: true
|
32
|
+
AllowedNames: ['io', 'id', 'to', 'by', 'on', 'in', 'at', '_'] # Defaults + _
|
33
|
+
|
34
|
+
Layout/MultilineMethodCallIndentation:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
Style/ParallelAssignment:
|
38
|
+
Enabled: true
|
39
|
+
|
40
|
+
Metrics/MethodLength:
|
41
|
+
Enabled: true
|
42
|
+
Max: 30
|