Skip to content

Commit b032a82

Browse files
authored
PHPLIB-798: Use more flexible assertions for connection counts (#894)
1 parent 8796589 commit b032a82

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

tests/SpecTests/PrimaryStepDownSpecTest.php

+20-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function setUp(): void
4343
}
4444

4545
/**
46-
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#id10
46+
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#not-primary-keep-connection-pool
4747
*/
4848
public function testNotPrimaryKeepsConnectionPool(): void
4949
{
@@ -79,7 +79,7 @@ public function testNotPrimaryKeepsConnectionPool(): void
7979
}
8080

8181
/**
82-
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#id11
82+
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#not-primary-reset-connection-pool
8383
*/
8484
public function testNotPrimaryResetConnectionPool(): void
8585
{
@@ -106,16 +106,19 @@ public function testNotPrimaryResetConnectionPool(): void
106106
$this->assertSame(self::NOT_PRIMARY, $e->getCode());
107107
}
108108

109-
// Verify that the connection pool has been cleared
110-
$this->assertSame($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
109+
/* Verify that the connection pool has been cleared and that a new
110+
* connection has been created. Use ">=" to allow for the possibility
111+
* that the server created additional connections unrelated to this
112+
* test. */
113+
$this->assertGreaterThanOrEqual($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
111114

112115
// Execute an insert into the test collection of a {test: 1} document and verify that it succeeds.
113116
$result = $this->insertDocuments(1);
114117
$this->assertSame(1, $result->getInsertedCount());
115118
}
116119

117120
/**
118-
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#id12
121+
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#shutdown-in-progress-reset-connection-pool
119122
*/
120123
public function testShutdownResetConnectionPool(): void
121124
{
@@ -142,16 +145,19 @@ public function testShutdownResetConnectionPool(): void
142145
$this->assertSame(self::SHUTDOWN_IN_PROGRESS, $e->getCode());
143146
}
144147

145-
// Verify that the connection pool has been cleared
146-
$this->assertSame($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
148+
/* Verify that the connection pool has been cleared and that a new
149+
* connection has been created. Use ">=" to allow for the possibility
150+
* that the server created additional connections unrelated to this
151+
* test. */
152+
$this->assertGreaterThanOrEqual($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
147153

148154
// Execute an insert into the test collection of a {test: 1} document and verify that it succeeds.
149155
$result = $this->insertDocuments(1);
150156
$this->assertSame(1, $result->getInsertedCount());
151157
}
152158

153159
/**
154-
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#id13
160+
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#interrupted-at-shutdown-reset-connection-pool
155161
*/
156162
public function testInterruptedAtShutdownResetConnectionPool(): void
157163
{
@@ -178,16 +184,19 @@ public function testInterruptedAtShutdownResetConnectionPool(): void
178184
$this->assertSame(self::INTERRUPTED_AT_SHUTDOWN, $e->getCode());
179185
}
180186

181-
// Verify that the connection pool has been cleared
182-
$this->assertSame($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
187+
/* Verify that the connection pool has been cleared and that a new
188+
* connection has been created. Use ">=" to allow for the possibility
189+
* that the server created additional connections unrelated to this
190+
* test. */
191+
$this->assertGreaterThanOrEqual($totalConnectionsCreated + 1, $this->getTotalConnectionsCreated());
183192

184193
// Execute an insert into the test collection of a {test: 1} document and verify that it succeeds.
185194
$result = $this->insertDocuments(1);
186195
$this->assertSame(1, $result->getInsertedCount());
187196
}
188197

189198
/**
190-
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#id9
199+
* @see https://github.com/mongodb/specifications/tree/master/source/connections-survive-step-down/tests#getmore-iteration
191200
*/
192201
public function testGetMoreIteration(): void
193202
{

0 commit comments

Comments
 (0)