Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mingyech committed Oct 19, 2023
1 parent 0df526a commit c3c80b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/dtls/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func heartbeatServer(stream msgStream, config *heartbeatConfig, maxMessageSize i
conf := validate(config)

c := &hbConn{stream: stream,
recvCh: make(chan errBytes),
recvCh: make(chan errBytes, maxMessageSize),
timeout: conf.Interval,
hb: conf.Heartbeat,
maxMessageSize: maxMessageSize,
Expand Down
9 changes: 6 additions & 3 deletions pkg/dtls/heartbeat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

var maxMsgSize = 65535
var conf = &heartbeatConfig{Interval: 1 * time.Second, Heartbeat: []byte("hihihihihihihihihi")}
var conf = &heartbeatConfig{Interval: 3 * time.Second, Heartbeat: []byte("hihihihihihihihihi")}

type mockStream struct {
rddl time.Time
Expand Down Expand Up @@ -118,9 +118,10 @@ func TestHeartbeatReadWrite(t *testing.T) {
require.Nil(t, err)

recvd := 0
sent := 0
toSend := []byte("testtt")
sendTimes := 5
sleepInterval := 400 * time.Millisecond
sleepInterval := 1000 * time.Millisecond
var wg sync.WaitGroup

wg.Add(1)
Expand All @@ -134,6 +135,7 @@ func TestHeartbeatReadWrite(t *testing.T) {
require.Nil(t, err)
n, err := s.Read(buffer)
if err != nil {
t.Log(err)
return
}
if string(toSend) != string(buffer[:n]) {
Expand All @@ -159,12 +161,13 @@ func TestHeartbeatReadWrite(t *testing.T) {
}
return
}
sent++
time.Sleep(sleepInterval)
}
}()

wg.Wait()
require.Equal(t, sendTimes, recvd)
require.Equal(t, sent, recvd)
}

func TestHeartbeatSend(t *testing.T) {
Expand Down

0 comments on commit c3c80b1

Please sign in to comment.