Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit Test Hangs When Retrieving Undefined Service Metadata Name #140

Open
GuyWhoKnowsTheGuy opened this issue May 19, 2023 · 1 comment
Open
Labels
kind/bug Some behavior is incorrect or out of spec

Comments

@GuyWhoKnowsTheGuy
Copy link

What happened?

My unit test hangs (deadlock?) when attempting to retrieve a service's metadata name, which happens to be undefined.

Expected Behavior

Accessing an undefined value should return a default value or throw an error.

Steps to reproduce

See gist

Output of pulumi about

CLI
Version 3.66.0
Go Version go1.20.3
Go Compiler gc

Host
OS Microsoft Windows 10 Pro
Version 10.0.19045 Build 19045
Arch x86_64

Backend
Name pulumi.com
URL https://app.pulumi.com/Afford2945
User Afford2945
Organizations Afford2945, RivalCoins

Pulumi locates its logs in C:\Users\Jerome\AppData\Local\Temp by default
warning: Failed to read project: no Pulumi.yaml project file found (searching upwards from C:\Users\Jerome). If you have not created a project yet, use pulumi new to do so: no project file found
warning: Failed to get information about the current stack: no Pulumi.yaml project file found (searching upwards from C:\Users\Jerome). If you have not created a project yet, use pulumi new to do so: no project file found
warning: A new version of Pulumi is available. To upgrade from version '3.66.0' to '3.68.0', visit https://pulumi.com/docs/reference/install/ for manual instructions and release notes.

Additional context

No response

Contributing

Vote on this issue by adding a 👍 reaction.
To contribute a fix for this issue, leave a comment (and link to your pull request, if you've opened one already).

@GuyWhoKnowsTheGuy GuyWhoKnowsTheGuy added kind/bug Some behavior is incorrect or out of spec needs-triage Needs attention from the triage team labels May 19, 2023
@mikhailshilkov mikhailshilkov transferred this issue from pulumi/pulumi-kubernetes May 22, 2023
@Frassle Frassle transferred this issue from pulumi/pulumi May 22, 2023
@Frassle Frassle removed the needs-triage Needs attention from the triage team label May 22, 2023
@Frassle
Copy link
Member

Frassle commented May 24, 2023

Copying gist here for posterity;

using Grpc.Core;
using NUnit.Framework;
using Pulumi;
using Pulumi.Testing;

namespace PulumiBug;

public static class ExtentionMethods
{
    public static TValue Value<TValue>(this Output<TValue> output) => GetValueAsync(output).Result;

    public static Task<T> GetValueAsync<T>(this Output<T> output)
    {
        var tcs = new TaskCompletionSource<T>();
        output.Apply(v =>
        {
            tcs.SetResult(v);
            return v;
        });
        return tcs.Task;
    }
}

public class MyStack : Stack
{
    public MyStack() 
    {
        var service = new Pulumi.Kubernetes.Core.V1.Service("MyServiceName", new());
    }
}

public class Mocks : IMocks
{
    public Task<object> CallAsync(MockCallArgs args)
    {
        return Task.FromResult((object)args.Args);
    }

    public Task<(string? id, object state)> NewResourceAsync(MockResourceArgs args)
    {
        return Task.FromResult((args.Id, (object)args.Inputs));
    }
}

[TestFixture]
public class Class1
{
    [Test]
    public async Task Test1()
    {
        var results = Pulumi.Deployment.TestAsync<MyStack>(new Mocks()).Result;

        var service = results.OfType<Pulumi.Kubernetes.Core.V1.Service>().First();
        var metaData = await service.Metadata.GetValueAsync();

        Assert.AreEqual("MyServiceName", metaData.Name);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec
Projects
None yet
Development

No branches or pull requests

2 participants