-
Notifications
You must be signed in to change notification settings - Fork 0
/
staging_test.go
78 lines (71 loc) · 1.74 KB
/
staging_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package gfal2
import (
"syscall"
"testing"
"time"
)
func getContext(t *testing.T) *Context {
context, err := NewContext()
if err != nil {
t.Fatal(err)
}
return context
}
func TestBringOnlineOk(t *testing.T) {
context := getContext(t)
token, err := context.BringOnline("mock://host/file?staging_time=0", 100, 100, false)
if err != nil {
t.Error(err)
}
if token == "" {
t.Error("Expecting a token")
}
t.Log(token)
}
func TestBringOnlineError(t *testing.T) {
context := getContext(t)
_, err := context.BringOnline("mock://host/file?staging_errno=2", 100, 100, false)
if err == nil {
t.Fatal("Expecting an error")
}
if err.Code() != 2 {
t.Error("Was expecting 2, got ", err.Code())
}
}
func TestPollList(t *testing.T) {
context := getContext(t)
urls := []string{
"mock://host/file?staging_time=5",
"mock://host/file?staging_time=5&staging_errno=2",
}
token, errors := context.BringOnlineList(urls, 100, 100, true)
if errors == nil {
t.Fatal("Expecting an array of errors")
}
for _, error := range errors {
if error == nil || error.Code() != syscall.EAGAIN {
t.Fatal("Was expecting an EAGAIN, got ", error)
}
}
time.Sleep(1 * time.Second)
errors = context.BringOnlinePollList(urls, token)
for _, error := range errors {
if error == nil || error.Code() != syscall.EAGAIN {
t.Fatal("Was expecting an EAGAIN, got ", error)
}
}
time.Sleep(5 * time.Second)
errors = context.BringOnlinePollList(urls, token)
if errors == nil {
t.Fatal("Expecting an array of errors")
}
if errors[0] != nil {
t.Error("Was expecting the first to succeed, got ", errors[0])
}
if errors[1] == nil {
t.Fatal("Was expecting the second to fail")
}
if errors[1].Code() != 2 {
t.Error("Was expecting 2, got ", errors[1].Code())
}
}