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
|
// check replica set authentication
var name = "logpath";
var token = "logpath_token";
var dbdir = MongoRunner.dataPath + name + "/"; // this will work under windows as well as linux
var basedir = MongoRunner.dataPath + name + "files" + "/";
var logdir = basedir + "logdir/";
var testdir = basedir + "testdir/";
var sfile = _isWindows() ? "NUL" : "/dev/null";
var logs = [token + "1", token + "2"];
var port = allocatePorts(6);
print("------ Creating directories");
// ensure log directory exists
assert(mkdir(basedir));
assert(mkdir(logdir));
assert(mkdir(testdir));
var cleanupFiles = function() {
var files = listFiles(logdir);
for (f in files) {
var name = files[f].name;
// mostly here for safety
if (name.indexOf(token) != -1) {
removeFile(name);
}
}
};
var logCount = function(fpattern, prefix) {
var files = listFiles(logdir);
var pat = RegExp(fpattern + (prefix ? "" : "$"));
var cnt = 0;
for (f in files) {
if (pat.test(files[f].name)) {
cnt++;
}
}
return cnt;
};
print("------ Cleaning up old files");
cleanupFiles();
// log should not exist
assert.eq(logCount(logs[0]), 0);
print("------ Start mongod with logpath set to new file");
var m = MongoRunner.runMongod({port: port[0], dbpath: dbdir, logpath: logdir + logs[0]});
// log should now exist (and no rotations should exist)
assert.eq(logCount(logs[0], true), 1);
MongoRunner.stopMongod(port[0]);
print("------ Start mongod with logpath set to existing file");
m = MongoRunner.runMongod({port: port[1], dbpath: dbdir, logpath: logdir + logs[0]});
// log should continue to exist
assert.eq(logCount(logs[0]), 1);
// but now there should be a rotation file
assert.eq(logCount(logs[0], true), 2);
cleanupFiles();
MongoRunner.stopMongod(port[1]);
// Blocking on SERVER-5117:
// MongoRunner currently hangs if mongod fails to start so these tests don't work
if (false) {
// only run forking test on *nix (not supported on Windows)
if (_isWindows()) {
print("------ Skipping fork tests... (Windows)");
} else {
print("------ Start mongod with logpath set to new file, fork");
var m = MongoRunner.runMongod(
{port: port[2], dbpath: dbdir, logpath: logdir + logs[1], fork: true});
// log should now exist (and no rotations should exist)
assert.eq(logCount(logs[1], true), 1);
MongoRunner.stopMongod(port[2]);
print("------ Start mongod with logpath set to existing file, fork");
m = MongoRunner.runMongod(
{port: port[3], dbpath: dbdir, logpath: logdir + logs[1], fork: true});
// log should continue to exist
assert.eq(logCount(logs[1]), 1);
// but now there should be a rotation file
assert.eq(logCount(logs[1], true), 2);
cleanupFiles();
MongoRunner.stopMongod(port[3]);
}
// the following tests depend on undefined behavior; assume that MongoRunner raises exception on
// error
print("------ Confirm that launch fails with directory");
assert.throws(function() {
MongoRunner.runMongod({port: port[4], dbpath: dbdir, logpath: testdir});
});
print("------ Confirm that launch fails with special file");
assert.throws(function() {
MongoRunner.runMongod({port: port[5], dbpath: dbdir, logpath: sfile});
});
}
|