Esempio n. 1
0
        static async Task <int> DestroyStack(string stack)
        {
            var projectName = Env.ProjectName;
            var currentDir  = Directory.GetCurrentDirectory();

            using var workspace = await LocalWorkspace.CreateAsync(
                      new LocalWorkspaceOptions {
                Program         = PulumiFn.Create <DefaultStack>(),
                ProjectSettings = new ProjectSettings(projectName, ProjectRuntimeName.Dotnet),
                WorkDir         = currentDir
            }
                      );

            var appStack = await WorkspaceStack.SelectAsync(stack, workspace);

            Information("Destroying {Stack}", stack);

            var result = await appStack.DestroyAsync(
                new DestroyOptions {
                OnStandardOutput = Information,
                OnStandardError  = Error
            }
                );

            return(result.Summary.Result == UpdateState.Succeeded ? 0 : -1);
        }
Esempio n. 2
0
        public async Task ConcurrentUpdateExceptionIsThrown()
        {
            var projectSettings = new ProjectSettings("command_exception_test", ProjectRuntimeName.NodeJS);

            using var workspace = await LocalWorkspace.CreateAsync(new LocalWorkspaceOptions
            {
                ProjectSettings = projectSettings,
            });

            var stackName = $"concurrent_update_stack{GetTestSuffix()}";
            await workspace.CreateStackAsync(stackName);

            try
            {
                var stack = await WorkspaceStack.SelectAsync(stackName, workspace);

                var hitSemaphore = false;
                using var semaphore = new SemaphoreSlim(0, 1);
                var program = PulumiFn.Create(() =>
                {
                    hitSemaphore = true;
                    // ReSharper disable once AccessToDisposedClosure
                    semaphore.Wait();
                    return(new Dictionary <string, object?>
                    {
                        ["test"] = "doesnt matter",
                    });
                });

                var upTask = stack.UpAsync(new UpOptions
                {
                    Program = program,
                });

                // wait until we hit semaphore
                while (!hitSemaphore)
                {
                    await Task.Delay(TimeSpan.FromSeconds(2));

                    if (upTask.IsFaulted)
                    {
                        throw upTask.Exception !;
                    }
                    else if (upTask.IsCompleted)
                    {
                        throw new Exception("never hit semaphore in first UP task");
                    }
                }

                // before releasing the semaphore, ensure another up throws
                var concurrentTask = stack.UpAsync(new UpOptions
                {
                    Program = program, // should never make it into this
                });

                await Assert.ThrowsAsync <ConcurrentUpdateException>(
                    () => concurrentTask);

                // finish first up call
                semaphore.Release();
                await upTask;
            }
            finally
            {
                await workspace.RemoveStackAsync(stackName);
            }
        }