Skip to content

Commit 0a7505f

Browse files
committed
test(spanner): avoid ID collisions by using self::randId() with a larger range
1 parent 8afd213 commit 0a7505f

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

Core/src/Testing/System/SystemTestCase.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public static function processQueue()
7676
*/
7777
public static function randId()
7878
{
79-
return rand(1, 9999999);
79+
return rand(1, 999999999);
8080
}
8181

8282
/**

Spanner/tests/System/PgTransactionTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function setUpTestFixtures(): void
5151
}
5252
self::setUpTestDatabase();
5353

54-
self::$id1 = rand(1000, 9999);
54+
self::$id1 = self::randId();
5555
self::$row = [
5656
'id' => self::$id1,
5757
'name' => uniqid(self::TESTING_PREFIX),
@@ -67,7 +67,7 @@ public function testRunTransaction()
6767
$db = self::$database;
6868

6969
$db->runTransaction(function ($t) {
70-
$id = rand(1, 346464);
70+
$id = self::randId();
7171
$t->insertOrUpdate(self::TEST_TABLE_NAME, [
7272
'id' => $id,
7373
'name' => uniqid(self::TESTING_PREFIX),
@@ -146,7 +146,7 @@ public function testRunTransactionWithDbRole($db, $values, $expected)
146146

147147
try {
148148
$db->runTransaction(function ($t) use ($values) {
149-
$id = rand(1, 346464);
149+
$id = self::randId();
150150
$t->insert(self::TEST_TABLE_NAME, $values);
151151

152152
$t->commit();

Spanner/tests/System/TransactionTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static function setUpTestFixtures(): void
5858
}
5959
self::setUpTestDatabase();
6060

61-
self::$id1 = rand(1000, 9999);
61+
self::$id1 = self::randId();
6262

6363
self::$row = [
6464
'id' => self::$id1,
@@ -74,7 +74,7 @@ public static function setUpTestFixtures(): void
7474
public function testRunTransaction()
7575
{
7676
$db = self::$database;
77-
$id = rand(1, 346464);
77+
$id = self::randId();
7878
$keySet = new KeySet([
7979
'keys' => [$id]
8080
]);
@@ -278,7 +278,7 @@ public function testRunTransactionWithDbRole($db, $values, $expected)
278278

279279
try {
280280
$db->runTransaction(function ($t) use ($values) {
281-
$id = rand(1, 346464);
281+
$id = self::randId();
282282
$t->insert(self::TEST_TABLE_NAME, $values);
283283

284284
$t->commit();
@@ -405,7 +405,7 @@ public function testRunTransactionILBWithMultipleOperations()
405405
$db = self::$database;
406406

407407
$res = $db->runTransaction(function ($t) {
408-
$id = rand(1, 346464);
408+
$id = self::randId();
409409
$row = [
410410
'id' => $id,
411411
'name' => uniqid(self::TESTING_PREFIX),
@@ -415,7 +415,7 @@ public function testRunTransactionILBWithMultipleOperations()
415415
$t->insert(self::TEST_TABLE_NAME, $row);
416416
$this->assertNull($t->id());
417417

418-
$id = rand(1, 346464);
418+
$id = self::randId();
419419
$t->executeUpdate(
420420
'INSERT INTO ' . self::TEST_TABLE_NAME . ' (id, name, birthday) VALUES (@id, @name, @birthday)',
421421
[
@@ -489,7 +489,7 @@ public function testTransactionToChannelAffinity()
489489
};
490490

491491
$res = $db->runTransaction(function ($t) use ($getChannel) {
492-
$id = rand(1, 346464);
492+
$id = self::randId();
493493
$row = [
494494
'id' => $id,
495495
'name' => uniqid(self::TESTING_PREFIX),
@@ -499,7 +499,7 @@ public function testTransactionToChannelAffinity()
499499
$t->insert(self::TEST_TABLE_NAME, $row);
500500
$this->assertNull($t->id());
501501

502-
$id = rand(1, 346464);
502+
$id = self::randId();
503503
$t->executeUpdate(
504504
'INSERT INTO ' . self::TEST_TABLE_NAME . ' (id, name, birthday) VALUES (@id, @name, @birthday)',
505505
[
@@ -677,7 +677,7 @@ private function getMultipleRows(int $total)
677677
// if $total is 10, then we will generate 9 rows.
678678
for ($i = 0; $i < $total; $i++) {
679679
$rows[] = [
680-
'id' => rand(1, 346464),
680+
'id' => self::randId(),
681681
'name' => uniqid(self::TESTING_PREFIX),
682682
'birthday' => new Date(new \DateTime('2000-01-01'))
683683
];

0 commit comments

Comments
 (0)