Skip to content

Commit

Permalink
add panic testcase.
Browse files Browse the repository at this point in the history
  • Loading branch information
Reasno committed May 28, 2020
1 parent 72ac8d0 commit b0668d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ext-swoole": ">=4.4",
"hyperf/pool": "^1.1",
"hyperf/process": "^1.1",
"spiral/goridge": "v2.3.0"
"spiral/goridge": "^2.4.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
Expand Down
10 changes: 10 additions & 0 deletions example/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ func (a *App) HelloError(name interface{}, r *interface{}) error {
return fmt.Errorf("%s, it is possible to return error", name)
}

func (a *App) HelloPanic(name interface{}, r *interface{}) (e error) {
defer func() {
if p := recover(); p != nil {
// Recovering from panic
e = fmt.Errorf("panic in go: %v", p)
}
}()
panic("Test if we can handle panic")
}

func main() {
if err := gotask.Register(new(App)); err != nil {
log.Fatalln(err)
Expand Down
12 changes: 12 additions & 0 deletions tests/Cases/CoroutineSocketTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ public function testConcurrently()
});
}

public function testPanic()
{
\Swoole\Coroutine\run(function () {
$task = make(SocketGoTask::class);
try {
$task->call('App.HelloPanic', '');
} catch (\Throwable $e) {
$this->assertInstanceOf(ServiceException::class, $e);
}
});
}

public function baseExample($task)
{
$this->assertEquals(
Expand Down

0 comments on commit b0668d5

Please sign in to comment.