-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmanager_test.go
More file actions
85 lines (75 loc) · 1.47 KB
/
Copy pathmanager_test.go
File metadata and controls
85 lines (75 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// This file is part of Botgoram
// Botgoram is free software: see LICENSE.txt for more details.
package botgoram
import (
"math/rand"
"testing"
"github.com/Patrolavia/telegram"
)
func makeTestUser(name string) *telegram.Victim {
return &telegram.Victim{
ID: int64(rand.Int()),
FirstName: name,
}
}
// test with 2 worker, 2 sender, no overflow, no block
func TestManagerWithTwoUser(t *testing.T) {
u1 := makeTestUser("user1")
u2 := makeTestUser("user2")
ch := make(chan *telegram.Message)
m := newManager(bySender, 2, ch)
m1 := &telegram.Message{
ID: 1,
Text: "test",
From: u1,
Chat: u1,
}
m2 := &telegram.Message{
ID: 2,
Text: "test",
From: u2,
Chat: u2,
}
go func() {
m.feed(m1)
m.feed(m2)
}()
actual := m.Begin()
if actual != m1 {
t.Errorf("Got different message in test 2 msg#1.")
}
actual = m.Begin()
if actual != m2 {
t.Errorf("Got different message in test 2 msg#2.")
}
}
func TestManagerWithOneUser(t *testing.T) {
u1 := makeTestUser("user1")
ch := make(chan *telegram.Message)
m := newManager(bySender, 2, ch)
m1 := &telegram.Message{
ID: 1,
Text: "test",
From: u1,
Chat: u1,
}
m2 := &telegram.Message{
ID: 2,
Text: "test",
From: u1,
Chat: u1,
}
go func() {
m.feed(m1)
m.feed(m2)
}()
actual := m.Begin()
if actual != m1 {
t.Errorf("Got different message in test 2 msg#1.")
}
m.Commit(m1)
actual = m.Begin()
if actual != m2 {
t.Errorf("Got different message in test 2 msg#2.")
}
}