summaryrefslogtreecommitdiff
path: root/jstests/dur/closeall.js
blob: f169f065826e7e6fab4626a36cffc165a911f7f3 (plain)
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
// testing closealldatabases concurrency
// this is also a test of recoverFromYield() as that will get exercised by the update

function f() {
    var variant = (new Date()) % 4;
    var path = "/data/db/closeall";
    var path2 = "/data/db/closeall_slave";
    var ourdb = "closealltest";

    print("closeall.js start mongod variant:" + variant);
    var options = (new Date()-0)%2==0 ? 8 : 0;
    print("closeall.js --durOptions " + options);
    var N = 1000;
    if (options) 
        N = 300;

    // use replication to exercise that code too with a close, and also to test local.sources with a close
    var conn = startMongodEmpty("--port", 30001, "--dbpath", path, "--dur", "--durOptions", options, "--master", "--oplogSize", 64);
    var connSlave = startMongodEmpty("--port", 30002, "--dbpath", path2, "--dur", "--durOptions", options, "--slave", "--source", "localhost:30001");

    var slave = connSlave.getDB(ourdb);

    // we'll use two connections to make a little parallelism
    var db1 = conn.getDB(ourdb);
    var db2 = new Mongo(db1.getMongo().host).getDB(ourdb);

    print("closeall.js run test");

    for( var i = 0; i < N; i++ ) { 
    	db1.foo.insert({x:1}); // this does wait for a return code so we will get some parallelism
	    if( i % 7 == 0 )
	        db1.foo.insert({x:99, y:2});
	    if( i %     49 == 0 )
	        db1.foo.update({ x: 99 }, { a: 1, b: 2, c: 3, d: 4 });
	    if (i % 100 == 0)
	        db1.foo.find();
	    if( i == 800 )
	        db1.foo.ensureIndex({ x: 1 });
        var res = null;
        try {
	    if( variant == 1 )
		sleep(0);
	    else if( variant == 2 ) 
		sleep(1);
	    else if( variant == 3 && i % 10 == 0 )
		print(i);
            res = db2.adminCommand("closeAllDatabases");
        }
        catch (e) {
            sleep(5000); // sleeping a little makes console output order prettier
            print("\n\n\nFAIL closeall.js closeAllDatabases command invocation threw an exception. i:" + i);
            try {
                print("getlasterror:");
                printjson(db2.getLastErrorObj());
                print("trying one more closealldatabases:");
                res = db2.adminCommand("closeAllDatabases");
                printjson(res);
            }
            catch (e) {
                print("got another exception : " + e);
            }
            print("\n\n\n");
            // sleep a little to capture possible mongod output?
            sleep(2000);
            throw e;
        }
	    assert( res.ok, "closeAllDatabases res.ok=false");
	}

	print("closeall.js end test loop.  slave.foo.count:");
	print(slave.foo.count());

	print("closeall.js shutting down servers");
	stopMongod(30002);
	stopMongod(30001);
}

f();
sleep(500);
print("SUCCESS closeall.js");