summaryrefslogtreecommitdiff
path: root/src/mongo/gotools/src/github.com/mongodb/mongo-tools/test/qa-tests/jstests/restore/norestore_profile.js
blob: 84ea4a5b5dca47d06b6af62a7daaab187031e326 (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
(function() {

  if (typeof getToolTest === 'undefined') {
    load('jstests/configs/plain_28.config.js');
  }

  var toolTest = getToolTest('norestore_profile');
  var commonToolArgs = getCommonToolArguments();

  var dbOne = toolTest.db.getSiblingDB('dbOne');
  // turn on the profiler
  dbOne.setProfilingLevel(2);

  // create some test data
  var data = [];
  for (var i=0; i<=100; i++) {
    data.push({_id: i, x: i*i});
  }
  dbOne.test.insertMany(data);
  // run some queries to end up in the profile collection
  dbOne.test.find({_id: 3});
  dbOne.test.find({_id: 30});
  dbOne.test.find({_id: 50});

  assert.gt(dbOne.system.profile.count(), 0, "profiler still empty after running test setup");

  // dump it
  var dumpTarget = 'norestore_profile';
  resetDbpath(dumpTarget);
  var ret = toolTest.runTool.apply(toolTest, ['dump']
    .concat(getDumpTarget(dumpTarget))
    .concat(commonToolArgs));
  assert.eq(0, ret);

  // turn off profiling and remove the profiler collection
  dbOne.setProfilingLevel(0);
  dbOne.system.profile.drop();
  assert.eq(dbOne.system.profile.count(), 0);

  // drop the database so it's empty
  dbOne.dropDatabase();

  // restore it, this should restore everything *except* the profile collection
  ret = toolTest.runTool.apply(toolTest, ['restore']
    .concat(getRestoreTarget(dumpTarget))
    .concat(commonToolArgs));
  assert.eq(0, ret, "restore to empty DB should have returned successfully");

  // check that the data actually got restored
  assert.gt(dbOne.test.count(), 100);

  // but the profile collection should still be empty
  assert.eq(dbOne.system.profile.count(), 0);

  // success
  toolTest.stop();

}());