summaryrefslogtreecommitdiff
path: root/jstests/core/clone_as_capped_nonexistant.js
blob: 1a87749002dcbe39a8164d67207f5885db177bca (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
/**
 * @tags: [
 *  requires_non_retryable_commands,
 *
 *  # capped collections is not available on embedded
 *  incompatible_with_embedded,
 * ]
 */

(function() {
    "use strict";
    // This test ensures that CloneCollectionAsCapped()ing a nonexistent collection will not
    // cause the server to abort (SERVER-13750)

    var dbname = "clone_collection_as_capped_nonexistent";
    var testDb = db.getSiblingDB(dbname);
    testDb.dropDatabase();

    // Database does not exist here
    var res = testDb.runCommand({cloneCollectionAsCapped: 'foo', toCollection: 'bar', size: 1024});
    assert.eq(res.ok, 0, "cloning a nonexistent collection to capped should not have worked");
    var isSharded = (db.isMaster().msg == "isdbgrid");

    assert.eq(
        res.errmsg,
        isSharded ? "no such cmd: cloneCollectionAsCapped" : "database " + dbname + " not found",
        "converting a nonexistent to capped failed but for the wrong reason");

    // Database exists, but collection doesn't
    testDb.coll.insert({});

    var res = testDb.runCommand({cloneCollectionAsCapped: 'foo', toCollection: 'bar', size: 1024});
    assert.eq(res.ok, 0, "cloning a nonexistent collection to capped should not have worked");
    assert.eq(res.errmsg,
              isSharded ? "no such cmd: cloneCollectionAsCapped"
                        : "source collection " + dbname + ".foo does not exist",
              "converting a nonexistent to capped failed but for the wrong reason");
}());