-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker_test.go
57 lines (50 loc) · 1.12 KB
/
worker_test.go
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
package reactor
import (
"testing"
)
func TestWorkerEmptyCode(t *testing.T) {
w, err := NewWorker("")
assertNil(t, err)
assertNotNil(t, w)
if w != nil {
assertEquals(t, checksum(""), w.version)
assertEquals(t, false, w.closed)
}
}
func TestWorkerCallCloseSafety(t *testing.T) {
w, err := NewWorker(`function render() { return '{"html": "<div>OK</div>"}'; }`)
assertNil(t, err)
for i := 0; i < 300; i++ {
if i > 100 && i < 200 {
go w.Close()
}
resp, err := w.Render(&Request{})
if err == nil {
assertContains(t, resp.HTML, "OK")
} else {
assertContains(t, err.Error(), "worker closed")
}
}
}
func TestWorkerInvalidCode(t *testing.T) {
w, err := NewWorker("throw 'hi';")
assertNil(t, w)
assertNotNil(t, err)
if err != nil {
assertContains(t, err.Error(), "Uncaught exception: hi")
}
}
func TestWorkerRenderClosed(t *testing.T) {
w, err := NewWorker("")
assertNil(t, err)
assertNotNil(t, w)
w.Close()
resp, err := w.Render(&Request{})
assertNil(t, resp)
assertNotNil(t, err)
if err != nil {
assertContains(t, err.Error(), "closed")
}
assertEquals(t, true, w.closed)
assertNil(t, w.ctx)
}