Skip to content

Commit d292c0c

Browse files
committed
Added functional throttle test.
1 parent 6f294bd commit d292c0c

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Specification/AsyncImportSpecification.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct(AsyncResource $resource)
3434
public function __clone()
3535
{
3636
$this->asyncResource = clone $this->asyncResource;
37+
// Throttle is not cloned because it most likely wants to be shared between imports.
3738

3839
parent::__clone();
3940
}

test/Integration/PorterAsyncTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,4 +198,22 @@ public function testPorterAwareAsyncTransformer(): void
198198
)
199199
);
200200
}
201+
202+
/**
203+
* Tests that the throttle is invoked during fetch operations.
204+
*/
205+
public function testThrottle(): \Generator
206+
{
207+
$throttle = $this->specification->getThrottle();
208+
$throttle->setMaxPerSecond(1);
209+
210+
$start = microtime(true);
211+
212+
$records = $this->porter->importAsync($this->specification);
213+
self::assertTrue($throttle->isThrottling());
214+
215+
yield $records->advance();
216+
self::assertFalse($throttle->isThrottling());
217+
self::assertGreaterThan(1, microtime(true) - $start);
218+
}
201219
}

0 commit comments

Comments
 (0)