temporalio / sdk-dotnet

Temporal .NET SDK
MIT License
375 stars 30 forks source link

[Bug] TaskQueue not forwarded when using Test Environment, breaks ContinueAsNew (hangs) #280

Open mnichols opened 2 months ago

mnichols commented 2 months ago

This test hangs because of a grpc reported missing TaskQueue (see below for error message):

using Temporalio.Client;
using Temporalio.Exceptions;
using Temporalio.Testing;
using Temporalio.Worker;
using Temporalio.Worker.Interceptors;
using Temporalio.Workflows;
using Xunit.Abstractions;

namespace Temporal.Curriculum.Timers.Tests.Orchestrations;
[Workflow]
public class Continued
{
    [WorkflowRun]
    public async Task  RunAsync(string arg)
    {
        if (string.Equals("can", arg))
        {
            return;
        }
        await Workflow.DelayAsync(2000);
        var canOpts = new ContinueAsNewOptions();
        throw Workflow.CreateContinueAsNewException<Continued>(wf => wf.RunAsync("can"), canOpts);
    }
}
public class ContinueAsNewTests : TestBase
{
    [Fact]
    public async Task CAN_WorksWithNoTaskQueue()
    {
        await using var env = await WorkflowEnvironment.StartTimeSkippingAsync();
        var workerOptions = new TemporalWorkerOptions("test") { LoggerFactory = LoggerFactory };
        workerOptions.AddWorkflow<Continued>(); 

        using var worker = new TemporalWorker(
            env.Client,
            workerOptions
        );
        await worker.ExecuteAsync(async () =>
        {
            var handle = await env.Client.StartWorkflowAsync<Continued>(wf => wf.RunAsync("first"),
                new WorkflowOptions("can1", worker.Options.TaskQueue!));

            var e = await Assert.ThrowsAsync<ContinueAsNewException>(async () =>
            {
                await handle.GetResultAsync();
            });

        });
    }

    public ContinueAsNewTests(ITestOutputHelper output) : base(output)
    {
    }
}

The error that prints before the test server hangs is:

2024-06-18T15:49:38.964086Z  WARN temporal_sdk_core::worker::workflow: Error while completing workflow activation error=status: InvalidArgument, message: "Missing TaskQueue.", details: [], metadata: MetadataMap { headers: {"content-type": "application/grpc"} }

It makes sense the test server hangs but the TaskQueue should really be getting auto-assigned by the Workflow if not provided explicitly.

cretz commented 2 months ago

This is caused/blocked by https://github.com/temporalio/sdk-java/issues/1424