mirror of
https://gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/snowflake.git
synced 2025-10-13 20:11:19 -04:00
broker tracking a heap of snowflakes
This commit is contained in:
parent
28e557fb43
commit
0cd6852ad0
5 changed files with 183 additions and 20 deletions
59
broker/snowflake-broker_test.go
Normal file
59
broker/snowflake-broker_test.go
Normal file
|
@ -0,0 +1,59 @@
|
|||
package snowflake_broker
|
||||
|
||||
import (
|
||||
"container/heap"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSnowflakeHeap(t *testing.T) {
|
||||
h := new(SnowflakeHeap)
|
||||
heap.Init(h)
|
||||
if 0 != h.Len() {
|
||||
t.Error("Unexpected length.")
|
||||
}
|
||||
s1 := new(Snowflake)
|
||||
s2 := new(Snowflake)
|
||||
s3 := new(Snowflake)
|
||||
s4 := new(Snowflake)
|
||||
|
||||
s1.clients = 4
|
||||
s2.clients = 5
|
||||
s3.clients = 3
|
||||
s4.clients = 1
|
||||
|
||||
heap.Push(h, s1)
|
||||
heap.Push(h, s2)
|
||||
heap.Push(h, s3)
|
||||
heap.Push(h, s4)
|
||||
|
||||
if 4 != h.Len() {
|
||||
t.Error("Unexpected length.")
|
||||
}
|
||||
|
||||
heap.Remove(h, 0)
|
||||
if 3 != h.Len() {
|
||||
t.Error("Unexpected length.")
|
||||
}
|
||||
|
||||
r := heap.Pop(h).(*Snowflake)
|
||||
if r.clients != 3 {
|
||||
t.Error("Unexpected clients: ", r.clients)
|
||||
}
|
||||
if r.index != -1 {
|
||||
t.Error("Unexpected index: ", r.index)
|
||||
}
|
||||
|
||||
r = heap.Pop(h).(*Snowflake)
|
||||
if r.clients != 4 {
|
||||
t.Error("Unexpected clients: ", r.clients)
|
||||
}
|
||||
|
||||
r = heap.Pop(h).(*Snowflake)
|
||||
if r.clients != 5 {
|
||||
t.Error("Unexpected clients: ", r.clients)
|
||||
}
|
||||
|
||||
if 0 != h.Len() {
|
||||
t.Error("Unexpected length.")
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue