-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess_manager_test.go
executable file
·63 lines (52 loc) · 1.65 KB
/
process_manager_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
package main
import (
//"github.com/bouk/monkey"
"log"
"os"
"testing"
"time"
)
func TestDoWorkProcess(t *testing.T) {
cleanTestDir()
defer cleanTestDir()
// Prepare Test
if err := os.MkdirAll("testDir/src/A/B", os.ModePerm); err != nil {
log.Fatal(err)
}
if err := os.MkdirAll("testDir/src/A/C", os.ModePerm); err != nil {
log.Fatal(err)
}
if err := os.MkdirAll("testDir/src/C", os.ModePerm); err != nil {
log.Fatal(err)
}
writeIntoFile("testDir/src/A/B/a.txt", "Hallo A_B_a")
writeIntoFile("testDir/src/A/b.txt", "Hallo A_c")
writeIntoFile("testDir/src/A/C/c.txt", "Hallo A_C_c")
writeIntoFile("testDir/src/C/d.txt", "Hallo C_d")
writeIntoFile("testDir/src/e.txt", "Hallo e")
args := Args{src: "/home/martin/Desktop/dev/KIT/Shuttle/testDir/src", duration: 3, user: "admin", pass: "admin", sendType: "zip"}
//start_time := time.Now()
done_files := make(chan string, 20)
quit := make(chan int)
pm := newProcessManager(&args, done_files)
go pm.doWork(quit)
quit <- 1
if len(done_files) > 0 {
t.Errorf("Done files channel shoud be empty but len(done_files)=%d", len(done_files))
}
//wayback := start_time.Add(time.Duration(3) * time.Second)
//patch := monkey.Patch(time.Now, func() time.Time { return wayback })
//defer patch.Unpatch()
time.Sleep(time.Duration(2900) * time.Millisecond)
go pm.doWork(quit)
quit <- 1
if len(done_files) > 0 {
t.Errorf("Done files channel shoud be empty but len(done_files)=%d", len(done_files))
}
time.Sleep(time.Duration(100) * time.Millisecond)
go pm.doWork(quit)
if len(done_files) > 3 {
t.Errorf("Done files channel shoud have > 3 elements. len(done_files)=%d", len(done_files))
}
quit <- 1
}