Skip to content

Commit dbb3755

Browse files
abnegateclaude
andcommitted
test(timeout): read the long text once and always drop the timeout collections
testQueryTimeout read the 14 MB fixture for each of its twenty documents and dropped its collection only when the find threw, and both timeout tests left their collection behind when a write before the timed read failed, failing the next run's create. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d6ff77f commit dbb3755

1 file changed

Lines changed: 41 additions & 33 deletions

File tree

‎tests/e2e/Adapter/Scopes/GeneralTests.php‎

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,30 +67,38 @@ public function testQueryTimeout(): void
6767

6868
$database->createCollection(Collection::create(id: 'global-timeouts'));
6969

70-
$database->createAttribute('global-timeouts', Attribute::string(key: 'longtext', size: 100000000, required: true));
70+
try {
71+
$database->createAttribute('global-timeouts', Attribute::string(key: 'longtext', size: 100000000, required: true));
7172

72-
for ($i = 0; $i < 20; $i++) {
73-
$database->createDocument('global-timeouts', new Document([
74-
'longtext' => file_get_contents(__DIR__.'/../../../resources/longtext.txt'),
75-
'$permissions' => [
76-
Permission::read(Role::any()),
77-
Permission::update(Role::any()),
78-
Permission::delete(Role::any()),
79-
],
80-
]));
81-
}
73+
$longtext = file_get_contents(__DIR__.'/../../../resources/longtext.txt');
74+
$this->assertIsString($longtext);
8275

83-
$database->setTimeout(1);
76+
for ($i = 0; $i < 20; $i++) {
77+
$database->createDocument('global-timeouts', new Document([
78+
'longtext' => $longtext,
79+
'$permissions' => [
80+
Permission::read(Role::any()),
81+
Permission::update(Role::any()),
82+
Permission::delete(Role::any()),
83+
],
84+
]));
85+
}
8486

85-
try {
86-
$database->find('global-timeouts', [
87-
Query::notEqual('longtext', 'appwrite'),
88-
]);
89-
$this->fail('Failed to throw exception');
90-
} catch (\Exception $e) {
87+
$database->setTimeout(1);
88+
89+
$thrown = null;
90+
try {
91+
$database->find('global-timeouts', [
92+
Query::notEqual('longtext', 'appwrite'),
93+
]);
94+
} catch (\Exception $e) {
95+
$thrown = $e;
96+
}
97+
98+
$this->assertInstanceOf(TimeoutException::class, $thrown, 'find() must throw a timeout exception');
99+
} finally {
91100
$database->clearTimeout();
92101
$database->deleteCollection('global-timeouts');
93-
$this->assertInstanceOf(TimeoutException::class, $e);
94102
}
95103
}
96104

@@ -1206,23 +1214,23 @@ public function testCountTimeout(): void
12061214

12071215
$database->createCollection(Collection::create(id: 'count-timeouts'));
12081216

1209-
$database->createAttribute('count-timeouts', Attribute::string(key: 'longtext', size: 100000000, required: true));
1217+
try {
1218+
$database->createAttribute('count-timeouts', Attribute::string(key: 'longtext', size: 100000000, required: true));
12101219

1211-
$longtext = file_get_contents(__DIR__.'/../../../resources/longtext.txt');
1212-
$this->assertIsString($longtext);
1220+
$longtext = file_get_contents(__DIR__.'/../../../resources/longtext.txt');
1221+
$this->assertIsString($longtext);
12131222

1214-
for ($i = 0; $i < 20; $i++) {
1215-
$database->createDocument('count-timeouts', new Document([
1216-
'longtext' => $longtext,
1217-
'$permissions' => [
1218-
Permission::read(Role::any()),
1219-
Permission::update(Role::any()),
1220-
Permission::delete(Role::any()),
1221-
],
1222-
]));
1223-
}
1223+
for ($i = 0; $i < 20; $i++) {
1224+
$database->createDocument('count-timeouts', new Document([
1225+
'longtext' => $longtext,
1226+
'$permissions' => [
1227+
Permission::read(Role::any()),
1228+
Permission::update(Role::any()),
1229+
Permission::delete(Role::any()),
1230+
],
1231+
]));
1232+
}
12241233

1225-
try {
12261234
$database->setTimeout(1);
12271235

12281236
$thrown = null;

0 commit comments

Comments
 (0)