-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
exit gracefully when SIGTERM error happens (#178)
* exit gracfully when SIGTERM error happens * Update version.rb * Add tests for lamby core hander, cmd and config move sig trap in lamby_core_test
- Loading branch information
1 parent
99dc164
commit 5f8e5ce
Showing
4 changed files
with
60 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Lamby | ||
VERSION = '5.2.0' | ||
VERSION = '5.2.1' | ||
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 |
---|---|---|
@@ -1,9 +1,53 @@ | ||
require 'test_helper' | ||
|
||
class LambyCoreSpec < LambySpec | ||
|
||
def setup | ||
@event = { 'httpMethod' => 'GET', 'path' => '/' } | ||
@context = TestHelpers::LambdaContext.new | ||
end | ||
|
||
it 'has a version number' do | ||
expect(Lamby::VERSION).wont_be_nil | ||
end | ||
|
||
it 'catches SIGTERM signal' do | ||
assert_raises(SystemExit) do | ||
Process.kill('TERM', Process.pid) | ||
sleep 0.1 # Give time for the signal to be processed | ||
end | ||
end | ||
|
||
it 'catches SIGINT signal' do | ||
assert_raises(SystemExit) do | ||
Process.kill('INT', Process.pid) | ||
sleep 0.1 # Give time for the signal to be processed | ||
end | ||
end | ||
|
||
it 'executes cmd method' do | ||
Lamby.config.stubs(:handled_proc).returns(->(_, _) {}) | ||
result = Lamby.cmd(event: @event, context: @context) | ||
|
||
assert result.is_a?(Hash), "Expected result to be a Hash, but got #{result.class}" | ||
assert_equal 200, result[:statusCode], "Expected statusCode to be 200, but got #{result[:statusCode]}" | ||
assert_includes result[:body], "Hello Lamby", "Expected body to contain 'Hello Lamby'" | ||
end | ||
|
||
it 'executes handler method' do | ||
app = Rack::Builder.new do | ||
run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['OK']] } | ||
end.to_app | ||
|
||
event = {'httpMethod' => 'GET'} | ||
result = Lamby.handler(app, event, @context) | ||
|
||
assert result.is_a?(Hash), "Expected result to be a Hash, but got #{result.class}" | ||
assert_equal 200, result[:statusCode], "Expected statusCode to be 200, but got #{result[:statusCode]}" | ||
assert_equal 'OK', result[:body], "Expected body to be 'OK', but got #{result[:body]}" | ||
end | ||
|
||
end | ||
it 'returns the configuration' do | ||
config = Lamby.config | ||
assert config.is_a?(Lamby::Configuration), "Expected config to be an instance of Lamby::Config, but got #{config.class}" | ||
end | ||
end |