summaryrefslogtreecommitdiff
path: root/jstests/repl/drop_dups.js
blob: f4f89b5d5c10deb8554dd9b77d8f70921952da0d (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

var rt = new ReplTest( "drop_dups" );

m = rt.start( true );
s = rt.start( false );

function block(){
    am.runCommand( { getlasterror : 1 , w : 2 , wtimeout : 3000 } )
}

am = m.getDB( "foo" );
as = s.getDB( "foo" );

function run( createInBackground ) {

    collName = "foo" + ( createInBackground ? "B" : "F" );
    
    am[collName].drop();
    am.blah.insert( { x : 1 } )
    assert.soon( function(){
        block();
        return as.blah.findOne();
    }
               );
        
    
    for ( i=0; i<10; i++ ) {
        am[collName].insert( { _id : i , x : Math.floor( i / 2 ) } )
    }
    
    block();
    
    as.runCommand( { "godinsert" : collName , obj : { _id : 101 , x : 20 } } );
    as.runCommand( { "godinsert" : collName , obj : { _id : 100 , x : 20 } } );
    as.getLastError();
    
    am.runCommand( { "godinsert" : collName , obj : { _id : 100 , x : 20 } } );
    am.runCommand( { "godinsert" : collName , obj : { _id : 101 , x : 20 } } );
    am.getLastError();

    assert.eq( as[collName].count() , am[collName].count() );
    
    function mymap(z) {
        return z._id + ":" + z.x + ",";
    }

    
    if ( am.serverStatus().mem.bits == 64 ) {
        assert.neq( tojson(am[collName].find().map(mymap)) , 
                    tojson(as[collName].find().map(mymap)) , "order is not supposed to be same on master and slave but it is" );
    }
    
    
    am[collName].ensureIndex( { x : 1 } , { unique : true , dropDups : true , background : createInBackground  } );
    am.blah.insert( { x : 1 } )
    block();

    assert.eq( 2 , am[collName].getIndexKeys().length , "A1 : " + createInBackground )
    assert.eq( 2 , as[collName].getIndexKeys().length , "A2 : " + createInBackground )
    
    assert.eq( am[collName].find().sort( { _id : 1 } ).map(mymap) , 
               as[collName].find().sort( { _id : 1 } ).map(mymap) , "different things dropped on master and slave" );
    
    
}

run( false )
run( true )

rt.stop()