File: mongocollection-createindex-timeout-002.phpt

package info (click to toggle)
php-mongo 1.5.7-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,040 kB
  • ctags: 2,802
  • sloc: ansic: 17,632; xml: 2,195; php: 1,630; pascal: 330; makefile: 52; sh: 39
file content (76 lines) | stat: -rw-r--r-- 1,988 bytes parent folder | download
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
--TEST--
MongoCollection::createIndex() options (non-streams)
--SKIPIF--
<?php require_once "tests/utils/standalone.inc"; ?>
<?php if (MONGO_STREAMS) { echo "skip This test requires non-stream connections"; } ?>
--FILE--
<?php
require_once "tests/utils/server.inc";
$m = mongo_standalone();
$name = dbname();
$colName = 'indexTest';
$d = $m->$name;
$ns = "$name.$colName";
$c = $d->$colName;

$c->drop();

/* setup */
echo "SETUP\n";
for($i = 0; $i < 5000; $i++) {
	    $c->insert( array( 'index' => $i ) );
}
echo "DONE\n";

function createResults($result)
{
    if ( $result === NULL ) {
        return;
    }
    echo $result['ok'] ? "OK\n" : "ERR\n";
}

function showIndexes($res)
{
    echo "Indexes:\n";
    foreach ( $res as $index ) {
        echo ' - ', $index['name'], ': ';
		if (array_key_exists( 'unique', $index ) && $index['unique'] == true ) {
			echo "unique ";
		}
		if (array_key_exists( 'dropDups', $index ) && $index['dropDups'] == true ) {
			echo "dropDups ";
		}
		if (array_key_exists( 'sparse', $index ) && $index['sparse'] == true ) {
			echo "sparse ";
		}
		if (array_key_exists( 'expireAfterSeconds', $index ) ) {
			echo "expireAfterSeconds({$index['expireAfterSeconds']}) ";
		}
        echo json_encode( $index['key'] ), "\n";
    }
}

try {
	createResults( $c->ensureIndex( array( "index" => 1, 'fieldA' => 1 ), array( 'socketTimeoutMS' => 1 )) );
} catch ( MongoCursorTimeoutException $e ) {
	echo $e->getCode(), ': ', $e->getMessage(), "\n";
}
try {
	createResults( $c->createIndex( array( "index" => 1, 'fieldB' => 1 ), array( 'socketTimeoutMS' => 1 )) );
} catch ( MongoCursorTimeoutException $e ) {
	echo $e->getCode(), ': ', $e->getMessage(), "\n";
}
sleep(3);
showIndexes($d->system->indexes->find( array('ns' => $ns) ));

?>
--EXPECTF--
SETUP
DONE
%s:%d: Timed out waiting for header data
%s:%d: Timed out waiting for header data
Indexes:
 - _id_: {"_id":1}
 - index_1_fieldA_1: {"index":1,"fieldA":1}
 - index_1_fieldB_1: {"index":1,"fieldB":1}