示例#1
0
        public Test_FixtureNoConnect(CadenceFixture fixture)
        {
            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats
            };

            if (fixture.Start(settings, keepConnection: true, keepOpen: CadenceTestHelper.KeepCadenceServerOpen, noClient: true) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client = CadenceClient.ConnectAsync(fixture.Settings).Result;

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).Wait();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).Wait();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
示例#2
0
        public Test_Replay(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            if (fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client;

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).WaitWithoutAggregate();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
示例#3
0
        public Test_EndToEnd(CadenceFixture fixture, ITestOutputHelper outputHelper)
        {
            TestHelper.ResetDocker(this.GetType());

            testWriter = new TestOutputWriter(outputHelper);

            // Initialize the Cadence fixture.

            var settings = new CadenceSettings()
            {
                DefaultDomain          = CadenceFixture.DefaultDomain,
                LogLevel               = CadenceTestHelper.LogLevel,
                CreateDomain           = true,
                Debug                  = CadenceTestHelper.Debug,
                DebugPrelaunched       = CadenceTestHelper.DebugPrelaunched,
                DebugDisableHeartbeats = CadenceTestHelper.DebugDisableHeartbeats,
                ClientIdentity         = CadenceTestHelper.ClientIdentity
            };

            if (fixture.Start(settings, reconnect: true, keepRunning: CadenceTestHelper.KeepCadenceServerOpen) == TestFixtureStatus.Started)
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };

                // Setup a service for activity dependency injection testing if it doesn't
                // already exist.

                if (NeonHelper.ServiceContainer.GetService <ActivityDependency>() == null)
                {
                    NeonHelper.ServiceContainer.AddSingleton(typeof(ActivityDependency), new ActivityDependency()
                    {
                        Hello = "World!"
                    });
                }

                // Auto register the test workflow and activity implementations.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();

                // Start the worker.

                client.StartWorkerAsync(CadenceTestHelper.TaskList).WaitWithoutAggregate();
            }
            else
            {
                this.fixture     = fixture;
                this.client      = fixture.Client;
                this.proxyClient = new HttpClient()
                {
                    BaseAddress = client.ProxyUri
                };
            }
        }
示例#4
0
        public CadenceTests(CadenceFixture fixture)
        {
            TestHelper.ResetDocker(this.GetType());

            var settings = new CadenceSettings()
            {
                DefaultDomain = "test-domain",
                LogLevel      = LogLevel.Info,
                CreateDomain  = true            // <-- this ensures that the default domain exists
            };

            // This starts/restarts the [nforgeio/cadence-dev] container for the first test
            // run in this class.  Subsequent tests run from the class will use the existing
            // container instance, saving time by not having to wait for Cadence and Cassandra
            // to spin up and be ready for business.
            //
            // The [keepOpen=true] parameter tells the fixture to let the container continue running
            // after all of the tests have completed.  This is useful for examining workflow histories
            // via the Cadence UX after the tests have completed.  You can view the Cadence portal at
            //
            //      http://localhost:8088
            //
            // You can pass [keepOpen=false] to have the fixture remove the container after the
            // test run if you wish.

            if (fixture.Start(settings, reconnect: true, keepRunning: true) == TestFixtureStatus.Started)
            {
                this.fixture = fixture;
                this.client  = fixture.Client;

                // Register the test workflow and activity implementations
                // from this assembly and start the worker.

                client.RegisterAssemblyAsync(Assembly.GetExecutingAssembly()).WaitWithoutAggregate();
                client.StartWorkerAsync("test-tasks").WaitWithoutAggregate();
            }
            else
            {
                this.fixture = fixture;
                this.client  = fixture.Client;
            }
        }
示例#5
0
        public async Task Multiple_TaskLists()
        {
            await SyncContext.Clear;

            // Test the scenario where there multiple clients without
            // workers that will be used to simulate apps that make calls
            // on workflows and then create multiple clients that register
            // different workflows and activities and then verify that
            // each of the workerless clients are able to execute workflows
            // and activities and that these end up being executed on the
            // correct clients.

            var clients = new List <CadenceClient>();

            try
            {
                // Initialize the non-worker clients.

                CadenceClient client1;
                CadenceClient client2;
                CadenceClient client3;

                clients.Add(client1 = await CadenceClient.ConnectAsync(fixture.Settings));
                clients.Add(client2 = await CadenceClient.ConnectAsync(fixture.Settings));
                clients.Add(client3 = await CadenceClient.ConnectAsync(fixture.Settings));

                // Initialize the worker clients.

                clients.Add(workerClient1 = await CadenceClient.ConnectAsync(fixture.Settings));
                clients.Add(workerClient2 = await CadenceClient.ConnectAsync(fixture.Settings));
                clients.Add(workerClient3 = await CadenceClient.ConnectAsync(fixture.Settings));

                // Start the workers.

                await workerClient1.RegisterActivityAsync <ActivityWorker1>();

                await workerClient1.RegisterWorkflowAsync <WorkflowWorker1>();

                await workerClient1.StartWorkerAsync("tasklist-1");

                await workerClient2.RegisterActivityAsync <ActivityWorker2>();

                await workerClient2.RegisterWorkflowAsync <WorkflowWorker2>();

                await workerClient2.StartWorkerAsync("tasklist-2");

                await workerClient3.RegisterActivityAsync <ActivityWorker3>();

                await workerClient3.RegisterWorkflowAsync <WorkflowWorker3>();

                await workerClient3.StartWorkerAsync("tasklist-3");

                // Execute each of the worker workflows WITHOUT the associated activities
                // from each client (both the worker and non-worker clients).

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker1>();

                    Assert.True(await stub.RunAsync(testActivity: false));
                }

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker2>();

                    Assert.True(await stub.RunAsync(testActivity: false));
                }

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker3>();

                    Assert.True(await stub.RunAsync(testActivity: false));
                }

                // Re-run the workflows calling the activities this time.

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker1>();

                    Assert.True(await stub.RunAsync(testActivity: true));
                }

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker2>();

                    Assert.True(await stub.RunAsync(testActivity: true));
                }

                foreach (var client in clients)
                {
                    var stub = client.NewWorkflowStub <IWorkflowWorker3>();

                    Assert.True(await stub.RunAsync(testActivity: true));
                }
            }
            finally
            {
                foreach (var client in clients)
                {
                    client.Dispose();
                }

                workerClient1 = null;
                workerClient2 = null;
                workerClient3 = null;
            }
        }
示例#6
0
        public async Task Worker()
        {
            await SyncContext.Clear;

            await client.RegisterDomainAsync("test-domain", ignoreDuplicates : true);

            // Verify that the stub builder methods don't barf.

            CadenceClient.BuildActivityStub <ITestActivity>();
            CadenceClient.BuildWorkflowStub <ITestWorkflow>();
            CadenceClient.BuildAssemblyStubs(Assembly.GetExecutingAssembly());

            // Verify that creating workers with the same attributes actually
            // return the pre-existing instance with an incremented reference
            // count.

            var activityWorker1 = await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableWorkflowWorker = true
            });

            Assert.Equal(0, activityWorker1.RefCount);

            var activityWorker2 = await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableWorkflowWorker = true
            });

            Assert.Same(activityWorker1, activityWorker2);
            Assert.Equal(1, activityWorker2.RefCount);

            var workflowWorker1 = await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableActivityWorker = true
            });

            Assert.Equal(0, workflowWorker1.RefCount);

            var workflowWorker2 = await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableActivityWorker = true
            });

            Assert.Same(workflowWorker1, workflowWorker2);
            Assert.Equal(1, workflowWorker2.RefCount);

            Assert.Same(workflowWorker1, workflowWorker2);
            Assert.Equal(1, workflowWorker2.RefCount);

            var worker1 = await client.StartWorkerAsync("tasks2");

            Assert.Equal(0, worker1.RefCount);

            var worker2 = await client.StartWorkerAsync("tasks2");

            Assert.Same(worker1, worker2);
            Assert.Equal(1, worker2.RefCount);

            // Verify the dispose/refcount behavior.

            activityWorker2.Dispose();
            Assert.False(activityWorker2.IsDisposed);
            Assert.Equal(0, activityWorker2.RefCount);

            activityWorker2.Dispose();
            Assert.True(activityWorker2.IsDisposed);
            Assert.Equal(-1, activityWorker2.RefCount);

            workflowWorker2.Dispose();
            Assert.False(workflowWorker2.IsDisposed);
            Assert.Equal(0, workflowWorker2.RefCount);

            workflowWorker2.Dispose();
            Assert.True(workflowWorker2.IsDisposed);
            Assert.Equal(-1, workflowWorker2.RefCount);

            // Verify that we're not allowed to restart workers.

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableWorkflowWorker = true
            }));

            await Assert.ThrowsAsync <InvalidOperationException>(async() => await client.StartWorkerAsync("tasks1", new WorkerOptions()
            {
                DisableActivityWorker = true
            }));
        }