Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module tokopedia/debuggingworkshop

go 1.17
7 changes: 5 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,15 @@ func sender(c chan signalData) {
}

func receiver(c chan signalData) {
// go tool pprof -alloc_space http://localhost:6060/debug/pprof/heap
// memory leak caused by repeated NewTimer instantiation. instantiate only once.
timeout := time.NewTimer(time.Second)
for {
select {
case signalData := <-c:
signalData.status = validateSignal(signalData.signal)
fmt.Println("Receiving Signal ", signalData.signal, " with status ", signalData.status)
case <-time.After(time.Second * 1):
case <-timeout.C:
fmt.Println("Got timeout while receiving the signal")
return
}
Expand Down Expand Up @@ -100,7 +103,7 @@ func evaluateNode(node1, node2 int) int {
case node2 < node1:
return 0
default:
return 0
return 1
}
}

Expand Down
14 changes: 14 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,20 @@ func Test_validateSignal(t *testing.T) {
},
want: "bad",
},
{
name: "bad signal 2",
args: args{
signal: []int{1, 1, 0, 0, 1, 0},
},
want: "bad",
},
{
name: "good signal 2",
args: args{
signal: []int{0, 1, 0, 0, 1, 1},
},
want: "good",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down