Skip to content

Commit

Permalink
Testing service (#197)
Browse files Browse the repository at this point in the history
* Testing service

* Run await test without time skipping

* Run await test without time skipping

* Add test service description

* Add trait

* Remove grpc extension requirement
  • Loading branch information
seregazhuk authored Jun 22, 2022
1 parent be29281 commit 8214713
Show file tree
Hide file tree
Showing 25 changed files with 1,202 additions and 8 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom
extensions: dom, sockets, grpc, curl

- name: Check Out Code
uses: actions/checkout@v2
Expand Down Expand Up @@ -65,7 +65,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: composer:v2
extensions: dom, sockets, curl
extensions: dom, sockets, grpc, curl

- name: Check Out Code
uses: actions/checkout@v2
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
with:
php-version: ${{ matrix.php }}
tools: composer:v2
extensions: dom, sockets, curl
extensions: dom, sockets, grpc, curl

- name: Check Out Code
uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
},
"autoload": {
"psr-4": {
"Temporal\\Api\\Testservice\\": "testing/api/testservice/Temporal/Api/Testservice",
"GPBMetadata\\Temporal\\Api\\Testservice\\": "testing/api/testservice/GPBMetadata/Temporal/Api/Testservice",
"Temporal\\Testing\\": "testing/src",
"GPBMetadata\\": "api/v1/GPBMetadata",
"Temporal\\": "src",
Expand Down
29 changes: 29 additions & 0 deletions testing/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,35 @@ $worker->registerActivity(MyActvivityMock::class);
$factory->run();
```

### Time management
By default, the test server starts with `--enable-time-skipping` option. It means that if the
workflow has a timer, the server doesn't wait for it and continues immediately. To change
this behaviour you can use `TestService` class:

```php
$testService = TestService::create('localhost:7233');
$testService->lockTimeSkipping();

// ...
$testService->unlockTimeSkipping();
```

Class `TestService` communicates with a test server and provides method for "time management". Time skipping
can be switched on/off with `unlockTimeSkipping()` and `lockTimeSkipping()` method.

In case you need to emulate some "waiting" on a test server, you can use `sleep(int secods)` or `sleepUntil(int $timestamp)` methods.

Current server time can be retrieved with `getCurrentTime(): Carbon` method.

For convenience if you don't want to skip time in the whole `TestCase` class use `WithoutTimeSkipping`:

```php
final class MyWorkflowTest extends TestCase
{
use WithoutTimeSkipping;
}
```




Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8214713

Please sign in to comment.