forked from glycerine/goq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofh_test.go
127 lines (103 loc) · 3.66 KB
/
ofh_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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package main
/*
// Under mangos instead of C-nanomsg, this test fails intermittently, and more
// often when run en-suite (go test -v) than it does when run
// stand-alone (go test -v -run TestSubmitDoesNotLeaveFileHandlesOpen001).
// So: We comment it out for now, now that we've shifted to mangos as our primary transport.
import (
"fmt"
cv "github.com/glycerine/goconvey/convey"
"os"
"testing"
"time"
)
// open-file-handles test
//
// We were seeing the goq server max out at 500 jobs submitted, because it
// is holding more than 1024 open file handles. So we need to be
// more frugal and keep all file handles closed when not in use.
// This test found a socket resource leak, and now that leak should
// stay fixed.
func TestSubmitDoesNotLeaveFileHandlesOpen001(t *testing.T) {
cv.Convey("job submits should not result in extra file handles being open on the server", t, func() {
// allow all child processes to communicate
// *** universal test cfg setup
skipbye := false
cfg := NewTestConfig()
defer cfg.ByeTestConfig(&skipbye)
// *** end universal test setup
// ensure any previous test has released our port before proceeding.
WaitUntilAddrAvailable(cfg.JservAddr())
cfg.DebugMode = true
childpid, err := NewExternalJobServ(cfg)
if err != nil {
panic(err)
}
fmt.Printf("[pid %d] spawned a new external JobServ with pid %d\n", os.Getpid(), childpid)
startingOFH := OpenFiles(childpid)
j := NewJob()
j.Cmd = "bin/good.sh"
sub, err := NewSubmitter(GenAddress(), cfg, false)
if err != nil {
panic(err)
}
sub.SubmitJobGetReply(j)
middleOFH := OpenFiles(childpid)
// test doing a bunch of submits
var mid2OFH []string
// each one seems to be leaking more anon inodes (linux)
// or pipes (osx).
//
// on linux: one anon_inode per client connection
// N =1 => 4 anon.inode leaked (23 fd in mid2OFH; 19 in starting)
// N =2 => 5 anon.inode leaked (24 fd in mid2OFH; 19 in starting)
// N =3 => 6 anon.inode leaked (25 fd in mid2OFH; 19 in starting)
// N =4 => 7 anon.inode leaked (26 fd in mid2OFH; 19 in starting).
//
// on osx:
// N =1 => 6 pipes leaked (24 fd in mid2OFH; 18 in starting).
// N =2 => 8 pipes leaked (26 fd in mid2OFH; 18 in starting).
// N =3 => 10 pipes leaked (28 fd in mid2OFH; 18 in starting).
// N =4 => 12 pipes leaked (28 fd in mid2OFH; 18 in starting).
//
N := 40
for i := 0; i < N; i++ {
sub2, err := NewSubmitter(GenAddress(), cfg, false)
if err != nil {
panic(err)
}
sub2.SubmitJobGetReply(j)
sub2.Bye()
}
mid2OFH = OpenFiles(childpid)
sub3, err := NewSubmitter(GenAddress(), cfg, false)
if err != nil {
panic(err)
}
sub3.SubmitJobGetReply(j)
sub3.Bye()
endingOFH := OpenFiles(childpid)
if len(endingOFH) != len(startingOFH) {
fmt.Printf("\n\n ending minus starting : \n")
ShowStrings(SetDiff(endingOFH, startingOFH))
fmt.Printf("\n\n middle minus starting : \n")
ShowStrings(SetDiff(middleOFH, startingOFH))
fmt.Printf("\n\n mid2(len %d) minus starting(len %d) : \n",
len(mid2OFH), len(startingOFH))
ShowStrings(SetDiff(mid2OFH, startingOFH))
fmt.Printf("\n mid2OFH is:\n")
ShowStrings(mid2OFH)
fmt.Printf("\n startingOFH is:\n")
ShowStrings(startingOFH)
fmt.Printf("\n\n starting minus ending : \n")
ShowStrings(SetDiff(startingOFH, endingOFH))
}
// *important* cleanup, and wait for cleanup to finish, so the next test can run.
sub.SubmitShutdownJob()
WaitForShutdownWithTimeout(childpid, cfg)
cv.So(len(mid2OFH), cv.ShouldBeLessThan, len(startingOFH)+8)
cv.So(len(middleOFH), cv.ShouldBeLessThan, len(startingOFH)+8)
cv.So(len(endingOFH), cv.ShouldBeLessThan, len(startingOFH)+8)
})
}
*/