Skip to content
This repository has been archived by the owner on Aug 17, 2020. It is now read-only.

Commit

Permalink
Panic handler test in scope
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Mar 2, 2020
1 parent 9d361a4 commit 3ee51f4
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions reflection/panic_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
package reflection
package reflection_test

import (
"fmt"
"sync/atomic"
"testing"
"time"

_ "go.undefinedlabs.com/scopeagent/autoinstrument"
"go.undefinedlabs.com/scopeagent/reflection"
)

func TestPanicHandler(t *testing.T) {
var panicHandlerVisit int32

AddPanicHandler(func(e interface{}) {
fmt.Println("PANIC HANDLER FOR:", e)
reflection.AddPanicHandler(func(e interface{}) {
t.Log("PANIC HANDLER FOR:", e)
atomic.AddInt32(&panicHandlerVisit, 1)
})

t.Run("OnPanic", func(t *testing.T) {
t.Run("OnPanic", func(t2 *testing.T) {
go func() {

defer func() {
if r := recover(); r != nil {
fmt.Println("PANIC RECOVERED")
t.Log("PANIC RECOVERED")
}
}()

fmt.Println("PANICKING!")
t.Log("PANICKING!")
panic("Panic error")

}()
Expand Down

0 comments on commit 3ee51f4

Please sign in to comment.