Skip to content

Commit 665b96a

Browse files
authored
Improving unit testing framework for history verification (#63)
* - minor CS * - more explicit unit test for history verification
1 parent 4d3aa23 commit 665b96a

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

tests/Functional/Client/ClientTestCase.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Temporal\Tests\Functional\Client;
1313

14+
use Temporal\Api\Enums\V1\EventType;
15+
use Temporal\Api\History\V1\HistoryEvent;
1416
use Temporal\Api\Workflowservice\V1\GetWorkflowExecutionHistoryRequest;
1517
use Temporal\Client\GRPC\ServiceClient;
1618
use Temporal\Client\WorkflowClient;
@@ -33,6 +35,23 @@ protected function createClient(string $connection = 'localhost:7233'): Workflow
3335
);
3436
}
3537

38+
protected function assertHistoryContainsActivity(
39+
WorkflowClient $client,
40+
WorkflowExecution $e,
41+
string $activity
42+
) {
43+
$this->assertHistoryContains(
44+
$client,
45+
$e,
46+
function (HistoryEvent $e) use ($activity) {
47+
return (
48+
$e->getEventType() === EventType::EVENT_TYPE_ACTIVITY_TASK_SCHEDULED
49+
&& $e->getActivityTaskScheduledEventAttributes()->getActivityType()->getName() == $activity
50+
);
51+
}
52+
);
53+
}
54+
3655
protected function assertHistoryContains(
3756
WorkflowClient $client,
3857
WorkflowExecution $e,

tests/Functional/Client/SagaTestCase.php

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111

1212
namespace Temporal\Tests\Functional\Client;
1313

14-
use Temporal\Api\Enums\V1\EventType;
15-
use Temporal\Api\History\V1\HistoryEvent;
1614
use Temporal\Exception\Client\WorkflowFailedException;
1715
use Temporal\Exception\Failure\ActivityFailure;
1816
use Temporal\Tests\Workflow\SagaWorkflow;
@@ -36,40 +34,8 @@ public function testGetResult()
3634
$this->assertInstanceOf(ActivityFailure::class, $e->getPrevious());
3735
}
3836

39-
$this->assertHistoryContains(
40-
$client,
41-
$run->getExecution(),
42-
function (HistoryEvent $e) {
43-
if ($e->getEventType() === EventType::EVENT_TYPE_ACTIVITY_TASK_SCHEDULED) {
44-
// compensation call
45-
if (
46-
$e->getActivityTaskScheduledEventAttributes()->getActivityType()->getName(
47-
) === 'SimpleActivity.lower'
48-
) {
49-
return true;
50-
}
51-
}
52-
53-
return false;
54-
}
55-
);
56-
57-
$this->assertHistoryContains(
58-
$client,
59-
$run->getExecution(),
60-
function (HistoryEvent $e) {
61-
if ($e->getEventType() === EventType::EVENT_TYPE_ACTIVITY_TASK_SCHEDULED) {
62-
// compensation call
63-
if (
64-
$e->getActivityTaskScheduledEventAttributes()->getActivityType()->getName(
65-
) === 'SimpleActivity.prefix'
66-
) {
67-
return true;
68-
}
69-
}
70-
71-
return false;
72-
}
73-
);
37+
$this->assertHistoryContainsActivity($client, $run->getExecution(), 'SimpleActivity.echo');
38+
$this->assertHistoryContainsActivity($client, $run->getExecution(), 'SimpleActivity.lower');
39+
$this->assertHistoryContainsActivity($client, $run->getExecution(), 'SimpleActivity.prefix');
7440
}
7541
}

0 commit comments

Comments
 (0)