Skip to content

Commit

Permalink
Set readPreference in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed May 22, 2024
1 parent 7d0538f commit 4b31535
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions GridFSAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use League\Flysystem\UnableToWriteFile;
use MongoDB\Client;
use MongoDB\Database;
use MongoDB\Driver\ReadPreference;
use function getenv;

/**
Expand Down Expand Up @@ -146,7 +147,7 @@ public function reading_last_revision(): void
$this->runScenario(
function () {
$this->givenWeHaveAnExistingFile('file.txt', 'version 1');
usleep(10);
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 2');

$this->assertSame('version 2', $this->adapter()->read('file.txt'));
Expand All @@ -165,7 +166,7 @@ public function listing_contents_last_revision(bool $deep): void
$this->runScenario(
function () use ($deep) {
$this->givenWeHaveAnExistingFile('file.txt', 'version 1');
usleep(10);
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 2');

$files = $this->adapter()->listContents('', $deep);
Expand Down Expand Up @@ -209,7 +210,9 @@ public function delete_all_revisions(): void
$this->runScenario(
function () {
$this->givenWeHaveAnExistingFile('file.txt', 'version 1');
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 2');
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 3');

$this->adapter()->delete('file.txt');
Expand All @@ -227,16 +230,15 @@ public function move_all_revisions(): void
$this->runScenario(
function () {
$this->givenWeHaveAnExistingFile('file.txt', 'version 1');
usleep(10);
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 2');
usleep(10);
usleep(1000);
$this->givenWeHaveAnExistingFile('file.txt', 'version 3');

$this->adapter()->move('file.txt', 'destination.txt', new Config());

$this->assertFalse($this->adapter()->fileExists('file.txt'));
$this->assertSame($this->adapter()->read('destination.txt'), 'version 3');

}
);
}
Expand All @@ -260,7 +262,9 @@ private static function getDatabase(): Database
{
$uri = getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017/';

$client = new Client($uri);
$client = new Client($uri, [], [
'readPreference' => new ReadPreference(ReadPreference::PRIMARY),
]);

return $client->selectDatabase(getenv('MONGODB_DATABASE') ?: 'flysystem_tests');
}
Expand Down

0 comments on commit 4b31535

Please sign in to comment.