mirror of
https://github.com/hanzokms/turn.git
synced 2026-10-30 20:50:36 +00:00
57 lines
1.2 KiB
Go
57 lines
1.2 KiB
Go
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package allocation
|
|
|
|
import (
|
|
"net"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/hanzokms/turn/v4/internal/proto"
|
|
)
|
|
|
|
func TestChannelBind(t *testing.T) {
|
|
c := newChannelBind(2 * time.Second)
|
|
|
|
if c.allocation.GetChannelByNumber(c.Number) != c {
|
|
t.Errorf("GetChannelByNumber(%d) shouldn't be nil after added to allocation", c.Number)
|
|
}
|
|
}
|
|
|
|
func TestChannelBindStart(t *testing.T) {
|
|
c := newChannelBind(2 * time.Second)
|
|
|
|
time.Sleep(3 * time.Second)
|
|
|
|
if c.allocation.GetChannelByNumber(c.Number) != nil {
|
|
t.Errorf("GetChannelByNumber(%d) should be nil if timeout", c.Number)
|
|
}
|
|
}
|
|
|
|
func TestChannelBindReset(t *testing.T) {
|
|
c := newChannelBind(3 * time.Second)
|
|
|
|
time.Sleep(2 * time.Second)
|
|
c.refresh(3 * time.Second)
|
|
time.Sleep(2 * time.Second)
|
|
|
|
if c.allocation.GetChannelByNumber(c.Number) == nil {
|
|
t.Errorf("GetChannelByNumber(%d) shouldn't be nil after refresh", c.Number)
|
|
}
|
|
}
|
|
|
|
func newChannelBind(lifetime time.Duration) *ChannelBind {
|
|
a := NewAllocation(nil, nil, nil)
|
|
|
|
addr, _ := net.ResolveUDPAddr("udp", "0.0.0.0:0")
|
|
c := &ChannelBind{
|
|
Number: proto.MinChannelNumber,
|
|
Peer: addr,
|
|
}
|
|
|
|
_ = a.AddChannelBind(c, lifetime)
|
|
|
|
return c
|
|
}
|