Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Worker/WorkerOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ class WorkerOptions
#[Marshal(name: 'MaxEagerActivityReservationsPerWorkflowTask')]
public ?int $maxEagerActivityReservationsPerWorkflowTask = null;

#[Marshal(name: 'DisablePayloadErrorLimit')]
public bool $disablePayloadErrorLimit = false;

/**
* Optional: Disable allowing workflow and activity functions that are
* registered with custom names from being able to be called with their
Expand Down Expand Up @@ -829,6 +832,13 @@ public function withMaxEagerActivityReservationsPerWorkflowTask(int $value): sel
return $self;
}

public function withDisablePayloadErrorLimit(bool $disable = true): self
{
$self = clone $this;
$self->disablePayloadErrorLimit = $disable;
return $self;
}

/**
* Optional: Disable allowing workflow and activity functions that are
* registered with custom names from being able to be called with their
Expand Down
1 change: 1 addition & 0 deletions tests/Acceptance/App/TaskQueueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class TaskQueueResolver
\Temporal\Tests\Acceptance\Extra\Versioning\Classic\ClassicTest::class,
\Temporal\Tests\Acceptance\Extra\Versioning\Deployment\DeploymentTest::class,
\Temporal\Tests\Acceptance\Extra\Activity\ActivityPaused\ActivityPausedTest::class,
\Temporal\Tests\Acceptance\Extra\Workflow\PayloadErrorLimitDisabled\PayloadErrorLimitDisabledTest::class,
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Workflow\PayloadErrorLimitDisabled;

use PHPUnit\Framework\Attributes\Test;
use Temporal\Api\Enums\V1\WorkflowTaskFailedCause;
use Temporal\Client\WorkflowClientInterface;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Exception\Client\WorkflowFailedException;
use Temporal\Tests\Acceptance\App\Attribute\Stub;
use Temporal\Tests\Acceptance\App\Attribute\Worker;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Worker\WorkerOptions;
use Temporal\Workflow\WorkflowExecutionStatus;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[Worker(options: [WorkerFactory::class, 'options'])]
class PayloadErrorLimitDisabledTest extends TestCase
{
#[Test]
public function serverTerminatesWorkflow(
#[Stub('Extra_Workflow_PayloadErrorLimitDisabled')]
WorkflowStubInterface $stub,
WorkflowClientInterface $client,
): void {
try {
$stub->getResult(timeout: 10);
self::fail('The Workflow must not complete');
} catch (WorkflowFailedException) {
}

self::assertSame(WorkflowExecutionStatus::Terminated, $stub->describe()->info->status);
foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) {
self::assertNotSame(
WorkflowTaskFailedCause::WORKFLOW_TASK_FAILED_CAUSE_PAYLOADS_TOO_LARGE,
$event->getWorkflowTaskFailedEventAttributes()?->getCause(),
);
}
}
}

class WorkerFactory
{
public static function options(): WorkerOptions
{
return WorkerOptions::new()->withDisablePayloadErrorLimit();
}
}

#[WorkflowInterface]
class TestWorkflow
{
#[WorkflowMethod(name: 'Extra_Workflow_PayloadErrorLimitDisabled')]
public function handle(): string
{
return \str_repeat('a', 3 * 1024 * 1024);
}
}
59 changes: 59 additions & 0 deletions tests/Acceptance/Extra/Workflow/PayloadErrorLimitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Workflow\PayloadErrorLimit;

use PHPUnit\Framework\Attributes\Test;
use Temporal\Api\Enums\V1\WorkflowTaskFailedCause;
use Temporal\Client\WorkflowClientInterface;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Tests\Acceptance\App\Attribute\Stub;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Workflow\WorkflowExecutionStatus;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

class PayloadErrorLimitTest extends TestCase
{
#[Test]
public function oversizedResultFailsWorkflowTask(
#[Stub('Extra_Workflow_PayloadErrorLimit')]
WorkflowStubInterface $stub,
WorkflowClientInterface $client,
): void {
$cause = self::waitForWorkflowTaskFailureCause($client, $stub);

self::assertSame(WorkflowTaskFailedCause::WORKFLOW_TASK_FAILED_CAUSE_PAYLOADS_TOO_LARGE, $cause);
self::assertSame(WorkflowExecutionStatus::Running, $stub->describe()->info->status);
$stub->terminate('test finished');
}

private static function waitForWorkflowTaskFailureCause(
WorkflowClientInterface $client,
WorkflowStubInterface $stub,
): int {
$deadline = \microtime(true) + 10;
do {
foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) {
$failed = $event->getWorkflowTaskFailedEventAttributes();
if ($failed !== null) {
return $failed->getCause();
}
}
\usleep(100_000);
} while (\microtime(true) < $deadline);

self::fail('The Workflow Task did not fail');
}
}

#[WorkflowInterface]
class TestWorkflow
{
#[WorkflowMethod(name: 'Extra_Workflow_PayloadErrorLimit')]
public function handle(): string
{
return \str_repeat('a', 3 * 1024 * 1024);
}
}
12 changes: 12 additions & 0 deletions tests/Unit/DTO/WorkerOptionsTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function testMarshalling(): void
'DisableEagerActivities' => false,
'MaxConcurrentEagerActivityExecutionSize' => 0,
'MaxEagerActivityReservationsPerWorkflowTask' => null,
'DisablePayloadErrorLimit' => false,
'DisableRegistrationAliasing' => false,
'BuildID' => "",
'DeploymentOptions' => null,
Expand Down Expand Up @@ -362,6 +363,17 @@ public function testMaxEagerActivityReservationsPerWorkflowTaskRejectsNonPositiv
(new WorkerOptions())->withMaxEagerActivityReservationsPerWorkflowTask(0);
}

public function testDisablePayloadErrorLimit(): void
{
$dto = new WorkerOptions();
$result = $dto->withDisablePayloadErrorLimit();

self::assertNotSame($dto, $result);
self::assertFalse($dto->disablePayloadErrorLimit);
self::assertTrue($result->disablePayloadErrorLimit);
self::assertTrue($this->marshal($result)['DisablePayloadErrorLimit']);
}

public function testDisableRegistrationAliasing(): void
{
$dto = new WorkerOptions();
Expand Down
Loading