Skip to content

Commit

Permalink
call cancel() function manually
Browse files Browse the repository at this point in the history
  • Loading branch information
bilalcaliskan committed Jan 3, 2022
1 parent 0eafc11 commit 0224aeb
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion internal/raw/raw_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ func TestStartFlooding(t *testing.T) {
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
ctx, cancel := context.WithTimeout(context.TODO(), time.Duration(tc.floodMilliSeconds)*time.Millisecond)
defer cancel()
t.Logf("starting flood, caseName=%s, floodType=%s, floodMilliSeconds=%d\n", tc.name, tc.floodType, tc.floodMilliSeconds)
go func() {
err := StartFlooding(tc.dstIp, tc.dstPort, tc.payloadLength, tc.floodType)
Expand All @@ -49,8 +48,10 @@ func TestStartFlooding(t *testing.T) {

select {
case <-time.After(120 * time.Second):
cancel()
t.Log("overslept")
case <-ctx.Done():
cancel()
t.Logf("context closed, caseName=%s, floodType=%s, floodMilliSeconds=%d\n", tc.name, tc.floodType, tc.floodMilliSeconds)
}
})
Expand Down

0 comments on commit 0224aeb

Please sign in to comment.