-
Notifications
You must be signed in to change notification settings - Fork 15
fix: fix RPC behavior when exception is thrown across boundary #301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
ngeojiajun-deriv
wants to merge
3
commits into
deriv-com:master
from
ngeojiajun-deriv:fix/proper-exception-marshalling
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,82 @@ | ||
use strict; | ||
use warnings; | ||
|
||
use Test::More; | ||
use Test::Deep; | ||
use Test::Fatal; | ||
use Test::Myriad; | ||
ngeojiajun-deriv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
use Future; | ||
use Future::AsyncAwait; | ||
use Object::Pad qw(:experimental); | ||
use Myriad::Exception::InternalError; | ||
|
||
my ($broken_services); | ||
|
||
# Example of some broken behavior that implementations can have | ||
package Test::BrokenServices { | ||
use Myriad::Service; | ||
async method normal : RPC (%args) { | ||
return {pong => 1}; | ||
} | ||
async method normal_dead : RPC (%args) { | ||
die "I am died"; | ||
} | ||
async method hash_dead : RPC (%args) { | ||
die {reason => "I am died"}; | ||
} | ||
async method blessed_dead : RPC (%args) { | ||
die bless {reason => "I am died"}, "Test::Exceptions"; | ||
} | ||
async method bubbled_dead : RPC (%args) { | ||
# Fake it as something is wrong with Myriad itself | ||
Myriad::Exception::InternalError->throw(); | ||
} | ||
} | ||
|
||
BEGIN { | ||
$broken_services = Test::Myriad->add_service(service => 'Test::BrokenServices'); | ||
} | ||
|
||
|
||
await Test::Myriad->ready(); | ||
|
||
subtest 'Normal RPC calls must succeeded as usual' => sub { | ||
my $resposne = $broken_services->call_rpc('normal')->get; | ||
cmp_deeply($resposne, {pong => 1}); | ||
}; | ||
|
||
subtest 'Dead RPC calls must have its exceptions bubbled up to caller' => sub { | ||
my $failure = exception { | ||
$broken_services->call_rpc('normal_dead')->get; | ||
}; | ||
is(ref $failure, "Myriad::Exception::RPC::RemoteException", "Correct error received by caller"); | ||
like($failure->reason, qr/reason=I am died/, "Correct error message"); | ||
}; | ||
|
||
subtest 'HASHREFs must not cross RPC boundary!' => sub { | ||
my $failure = exception { | ||
$broken_services->call_rpc('hash_dead')->get; | ||
}; | ||
is(ref $failure, "Myriad::Exception::RPC::RemoteException", "Correct error received by caller"); | ||
like($failure->reason, qr/reason=HASH\(0x[a-zA-Z0-9]+\)/, "Correct error message"); | ||
}; | ||
|
||
subtest 'blessed HASHREFs must not cross RPC boundary!' => sub { | ||
my $failure = exception { | ||
$broken_services->call_rpc('blessed_dead')->get; | ||
}; | ||
is(ref $failure, "Myriad::Exception::RPC::RemoteException", "Correct error received by caller"); | ||
like($failure->reason, qr/reason=Test::Exceptions=HASH\(0x[a-zA-Z0-9]+\)/, "Correct error message"); | ||
}; | ||
|
||
subtest 'Internal Myriad errors on remote must not appear as local Myriad error!' => sub { | ||
my $failure = exception { | ||
$broken_services->call_rpc('bubbled_dead')->get; | ||
}; | ||
is(ref $failure, "Myriad::Exception::RPC::RemoteException", "Correct error received by caller"); | ||
is($failure->reason, 'Remote exception is thrown: Internal error (category=internal)', "Correct error message"); | ||
}; | ||
|
||
done_testing(); | ||
|
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.