File: loadserverscripts.js

package info (click to toggle)
mongodb 1%3A2.4.10-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 82,464 kB
  • sloc: cpp: 740,225; ansic: 152,098; sh: 13,820; python: 11,864; makefile: 1,012; perl: 922; pascal: 617; java: 452; lisp: 222; asm: 174
file content (57 lines) | stat: -rw-r--r-- 1,847 bytes parent folder | download | duplicates (3)
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

// Test db.loadServerScripts()

var testdb = db.getSisterDB("loadserverscripts");

jsTest.log("testing db.loadServerScripts()");
var x;

// assert._debug = true;

// clear out any data from old tests
testdb.system.js.remove();
delete myfunc;
delete myfunc2;

x = testdb.system.js.findOne();
assert.isnull(x, "Test for empty collection");

// User functions should not be defined yet
assert.eq( typeof myfunc, "undefined", "Checking that myfunc() is undefined" );
assert.eq( typeof myfunc2, "undefined", "Checking that myfunc2() is undefined" );

// Insert a function in the context of this process: make sure it's in the collection
testdb.system.js.insert( { _id: "myfunc", "value": function(){ return "myfunc"; } } );
x = testdb.system.js.count();
assert.eq( x, 1, "Should now be one function in the system.js collection");

// Load that function
testdb.loadServerScripts();
assert.eq( typeof myfunc, "function", "Checking that myfunc() loaded correctly" );

// Make sure it works
x = myfunc();
assert.eq(x, "myfunc", "Checking that myfunc() returns the correct value");

// Insert value into collection from another process
var coproc = startParallelShell(
        'db.getSisterDB("loadserverscripts").system.js.insert' +
        '    ( {_id: "myfunc2", "value": function(){ return "myfunc2"; } } );' +
        'db.getLastError();'
                );
// wait for results
coproc();

// Make sure the collection's been updated
x = testdb.system.js.count();
assert.eq( x, 2, "Should now be two functions in the system.js collection");


// Load the new functions: test them as above
testdb.loadServerScripts();
assert.eq( typeof myfunc2, "function", "Checking that myfunc2() loaded correctly" );
x = myfunc2();
assert.eq(x, "myfunc2", "Checking that myfunc2() returns the correct value");

jsTest.log("completed test of db.loadServerScripts()");