[sdk/nodejs] Fix construct to wait for RPC operations to complete (#6452)

This change fixes the provider implementation of `Construct` for multi-lang components written in Node.js to wait for any in-flight RPCs to finish before returning the results, s.t. all registered child resources are created.

In additional, invocations of `construct` are now serialized so that each call runs one after another, avoiding concurrent runs, since `construct` modifies global state. We'll follow-up with a more general concurrency fix to allow nested `construct` calls within the same provider.
This commit is contained in:
Justin Van Patten 2021-04-05 11:11:27 -07:00 committed by GitHub
parent dcf4359c57
commit 394f79f27f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 763 additions and 6 deletions

View file

@ -11,3 +11,6 @@
- [automation/dotnet] Environment variable value type is now nullable.
[#6520](https://github.com/pulumi/pulumi/pull/6520)
- [sdk/nodejs] Fix `Construct` to wait for child resources of a multi-lang components to be created.
[#6452](https://github.com/pulumi/pulumi/pull/6452

View file

@ -54,6 +54,7 @@ test_fast:: build
test_build:: $(SUB_PROJECTS:%=%_install)
cd tests/integration/construct_component/testcomponent && yarn install && yarn link @pulumi/pulumi && yarn run tsc
cd tests/integration/construct_component_slow/testcomponent && yarn install && yarn link @pulumi/pulumi && yarn run tsc
test_all:: build test_build $(SUB_PROJECTS:%=%_install)
cd pkg && $(GO_TEST) ${PROJECT_PKGS}

View file

@ -277,13 +277,18 @@
<Target Name="TestDependencies">
<Exec Command="yarn install"
WorkingDirectory="$(TestsDirectory)\integration\construct_component\testcomponent" />
<Exec Command="yarn link @pulumi/pulumi"
WorkingDirectory="$(TestsDirectory)\integration\construct_component\testcomponent" />
WorkingDirectory="$(TestsDirectory)\integration\construct_component\testcomponent" />
<Exec Command="yarn link @pulumi/pulumi"
WorkingDirectory="$(TestsDirectory)\integration\construct_component\testcomponent" />
<Exec Command="yarn install"
WorkingDirectory="$(TestsDirectory)\integration\construct_component_slow\testcomponent" />
<Exec Command="yarn link @pulumi/pulumi"
WorkingDirectory="$(TestsDirectory)\integration\construct_component_slow\testcomponent" />
</Target>
<Target Name="TestBuild">
<Exec Command="yarn run tsc" WorkingDirectory="$(TestsDirectory)\integration\construct_component\testcomponent" />
<Exec Command="yarn run tsc" WorkingDirectory="$(TestsDirectory)\integration\construct_component_slow\testcomponent" />
</Target>
<!-- Tests -->

View file

@ -38,6 +38,9 @@ class Server implements grpc.UntypedServiceImplementation {
readonly engineAddr: string;
readonly provider: Provider;
/** Queue of construct calls. */
constructQueue = Promise.resolve();
constructor(engineAddr: string, provider: Provider) {
this.engineAddr = engineAddr;
this.provider = provider;
@ -248,6 +251,19 @@ class Server implements grpc.UntypedServiceImplementation {
}
public async construct(call: any, callback: any): Promise<void> {
// Serialize invocations of `construct` so that each call runs one after another, avoiding concurrent runs.
// We do this because `construct` has to modify global state to reset the SDK's runtime options.
// This is a short-term workaround to provide correctness, but likely isn't sustainable long-term due to the
// limits it places on parallelism. We will likely want to investigate if it's possible to run each invocation
// in its own context, possibly using Node's `createContext` API:
// https://nodejs.org/api/vm.html#vm_vm_createcontext_contextobject_options
const res = this.constructQueue.then(() => this.constructImpl(call, callback));
// tslint:disable:no-empty
this.constructQueue = res.catch(() => {});
return res;
}
async constructImpl(call: any, callback: any): Promise<void> {
try {
const req: any = call.request;
const type = req.getType();
@ -308,6 +324,7 @@ class Server implements grpc.UntypedServiceImplementation {
};
const result = await this.provider.construct(name, type, inputs, opts);
const resp = new provproto.ConstructResponse();
resp.setUrn(await output(result.urn).promise());
@ -321,6 +338,9 @@ class Server implements grpc.UntypedServiceImplementation {
}
resp.setState(structproto.Struct.fromJavaScript(state));
// Wait for RPC operations to complete and disconnect.
await runtime.disconnect();
callback(undefined, resp);
} catch (e) {
console.error(`${e}: ${e.stack}`);

View file

@ -0,0 +1,353 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!?*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/

View file

@ -0,0 +1,11 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class Component : Pulumi.ComponentResource
{
public Component(string name, ComponentResourceOptions opts = null)
: base("testcomponent:index:Component", name, ResourceArgs.Empty, opts, remote: true)
{
}
}

View file

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View file

@ -0,0 +1,11 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
using Pulumi;
class MyStack : Stack
{
public MyStack()
{
var componentA = new Component("a");
}
}

View file

@ -0,0 +1,7 @@
using System.Threading.Tasks;
using Pulumi;
class Program
{
static Task<int> Main() => Deployment.RunAsync<MyStack>();
}

View file

@ -0,0 +1,3 @@
name: construct_component_slow_dotnet
description: A program that constructs a remote component resource with a child resource that takes a long time to be created.
runtime: dotnet

View file

@ -0,0 +1,3 @@
name: construct_component_slow_go
description: A program that constructs a remote component resource with a child resource that takes a long time to be created.
runtime: go

View file

@ -0,0 +1,29 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
package main
import (
"github.com/pulumi/pulumi/sdk/v2/go/pulumi"
)
type Component struct {
pulumi.ResourceState
}
func NewComponent(ctx *pulumi.Context, name string, opts ...pulumi.ResourceOption) (*Component, error) {
var resource Component
err := ctx.RegisterRemoteComponentResource("testcomponent:index:Component", name, nil, &resource, opts...)
if err != nil {
return nil, err
}
return &resource, nil
}
func main() {
pulumi.Run(func(ctx *pulumi.Context) error {
if _, err := NewComponent(ctx, "a"); err != nil {
return err
}
return nil
})
}

View file

@ -0,0 +1,3 @@
/.pulumi/
/bin/
/node_modules/

View file

@ -0,0 +1,3 @@
name: construct_component_slow_nodejs
description: A program that constructs a remote component resource with a child resource that takes a long time to be created.
runtime: nodejs

View file

@ -0,0 +1,9 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
import * as pulumi from "@pulumi/pulumi";
export class Component extends pulumi.ComponentResource {
constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
super("testcomponent:index:Component", name, {}, opts, true);
}
}

View file

@ -0,0 +1,5 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved.
import { Component } from "./component";
const componentA = new Component("a");

View file

@ -0,0 +1,10 @@
{
"name": "steps",
"license": "Apache-2.0",
"devDependencies": {
"typescript": "^3.0.0"
},
"peerDependencies": {
"@pulumi/pulumi": "latest"
}
}

View file

@ -0,0 +1,5 @@
*.pyc
/.pulumi/
/dist/
/*.egg-info
venv/

View file

@ -0,0 +1,3 @@
name: construct_component_slow_py
description: A program that constructs a remote component resource with a child resource that takes a long time to be created.
runtime: python

View file

@ -0,0 +1,5 @@
# Copyright 2016-2021, Pulumi Corporation. All rights reserved.
from component import Component
component_a = Component("a")

View file

@ -0,0 +1,10 @@
# Copyright 2016-2021, Pulumi Corporation. All rights reserved.
from typing import Any, Optional
import pulumi
class Component(pulumi.ComponentResource):
def __init__(self, name: str, opts: Optional[pulumi.ResourceOptions] = None):
props = dict()
super().__init__("testcomponent:index:Component", name, props, opts, True)

View file

@ -0,0 +1,70 @@
// Copyright 2016-2021, Pulumi Corporation. All rights reserved
import * as pulumi from "@pulumi/pulumi";
import * as dynamic from "@pulumi/pulumi/dynamic";
import * as provider from "@pulumi/pulumi/provider";
// The component has a child resource that takes a long time to be created.
// We want to ensure the component's slow child resource will actually be created when the
// component is created inside `construct`.
const CREATION_DELAY = 15 * 1000; // 15 second delay in milliseconds
let currentID = 0;
class SlowResource extends dynamic.Resource {
constructor(name: string, opts?: pulumi.CustomResourceOptions) {
const provider = {
// Return the result after a delay to simulate a resource that takes a long time
// to be created.
create: async (inputs: any) => {
await delay(CREATION_DELAY);
return {
id: (currentID++).toString(),
outs: undefined,
};
},
};
super(provider, name, {}, opts);
}
}
function delay(timeout: number): Promise<void> {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, timeout);
});
}
class Component extends pulumi.ComponentResource {
constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
super("testcomponent:index:Component", name, {}, opts);
// Create a child resource that takes a long time in the provider to be created.
new SlowResource(`child-${name}`, {parent: this});
}
}
class Provider implements provider.Provider {
public readonly version = "0.0.1";
construct(name: string, type: string, inputs: pulumi.Inputs,
options: pulumi.ComponentResourceOptions): Promise<provider.ConstructResult> {
if (type != "testcomponent:index:Component") {
throw new Error(`unknown resource type ${type}`);
}
// Create the component with a slow child resource.
const component = new Component(name, options);
return Promise.resolve({
urn: component.urn,
state: {},
});
}
}
export function main(args: string[]) {
return provider.main(new Provider(), args);
}
main(process.argv.slice(2));

View file

@ -0,0 +1,11 @@
{
"name": "pulumi-resource-testcomponent",
"main": "index.js",
"devDependencies": {
"typescript": "^3.0.0",
"@types/node": "latest"
},
"peerDependencies": {
"@pulumi/pulumi": "latest"
}
}

View file

@ -0,0 +1,3 @@
#!/bin/bash
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
node $SCRIPT_DIR/bin $@

View file

@ -0,0 +1,4 @@
@echo off
setlocal
set SCRIPT_DIR=%~dp0
@node "%SCRIPT_DIR%/bin" %*

View file

@ -0,0 +1,20 @@
{
"compilerOptions": {
"strict": true,
"outDir": "bin",
"target": "es2016",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": false,
"stripInternal": true,
"experimentalDecorators": true,
"pretty": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.ts",
]
}

View file

@ -245,10 +245,44 @@ func TestConstructDotnet(t *testing.T) {
integration.ProgramTest(t, opts)
}
// Test remote component construction with a child resource that takes a long time to be created, ensuring it's created.
func TestConstructSlowDotnet(t *testing.T) {
pathEnv, err := testComponentSlowPathEnv()
if err != nil {
t.Fatalf("failed to build test component PATH: %v", err)
}
// TODO[pulumi/pulumi#5455]: Dynamic providers fail to load when used from multi-lang components.
// Until we've addressed this, set PULUMI_TEST_YARN_LINK_PULUMI, which tells the integration test
// module to run `yarn install && yarn link @pulumi/pulumi` in the .NET program's directory, allowing
// the Node.js dynamic provider plugin to load.
// When the underlying issue has been fixed, the use of this environment variable inside the integration
// test module should be removed.
const testYarnLinkPulumiEnv = "PULUMI_TEST_YARN_LINK_PULUMI=true"
var opts *integration.ProgramTestOptions
opts = &integration.ProgramTestOptions{
Env: []string{pathEnv, testYarnLinkPulumiEnv},
Dir: filepath.Join("construct_component_slow", "dotnet"),
Dependencies: []string{"Pulumi"},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 5, len(stackInfo.Deployment.Resources)) {
stackRes := stackInfo.Deployment.Resources[0]
assert.NotNil(t, stackRes)
assert.Equal(t, resource.RootStackType, stackRes.Type)
assert.Equal(t, "", string(stackRes.Parent))
}
},
}
integration.ProgramTest(t, opts)
}
func TestGetResourceDotnet(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dependencies: []string{"Pulumi"},
Dir: filepath.Join("get_resource", "dotnet"),
Dependencies: []string{"Pulumi"},
Dir: filepath.Join("get_resource", "dotnet"),
AllowEmptyPreviewChanges: true,
})
}

View file

@ -175,6 +175,42 @@ func TestConstructGo(t *testing.T) {
integration.ProgramTest(t, opts)
}
// Test remote component construction with a child resource that takes a long time to be created, ensuring it's created.
func TestConstructSlowGo(t *testing.T) {
pathEnv, err := testComponentSlowPathEnv()
if err != nil {
t.Fatalf("failed to build test component PATH: %v", err)
}
// TODO[pulumi/pulumi#5455]: Dynamic providers fail to load when used from multi-lang components.
// Until we've addressed this, set PULUMI_TEST_YARN_LINK_PULUMI, which tells the integration test
// module to run `yarn install && yarn link @pulumi/pulumi` in the Go program's directory, allowing
// the Node.js dynamic provider plugin to load.
// When the underlying issue has been fixed, the use of this environment variable inside the integration
// test module should be removed.
const testYarnLinkPulumiEnv = "PULUMI_TEST_YARN_LINK_PULUMI=true"
var opts *integration.ProgramTestOptions
opts = &integration.ProgramTestOptions{
Env: []string{pathEnv, testYarnLinkPulumiEnv},
Dir: filepath.Join("construct_component_slow", "go"),
Dependencies: []string{
"github.com/pulumi/pulumi/sdk/v2",
},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 5, len(stackInfo.Deployment.Resources)) {
stackRes := stackInfo.Deployment.Resources[0]
assert.NotNil(t, stackRes)
assert.Equal(t, resource.RootStackType, stackRes.Type)
assert.Equal(t, "", string(stackRes.Parent))
}
},
}
integration.ProgramTest(t, opts)
}
func TestGetResourceGo(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dependencies: []string{

View file

@ -697,6 +697,32 @@ func TestConstructNode(t *testing.T) {
integration.ProgramTest(t, opts)
}
// Test remote component construction with a child resource that takes a long time to be created, ensuring it's created.
func TestConstructSlowNode(t *testing.T) {
pathEnv, err := testComponentSlowPathEnv()
if err != nil {
t.Fatalf("failed to build test component PATH: %v", err)
}
var opts *integration.ProgramTestOptions
opts = &integration.ProgramTestOptions{
Env: []string{pathEnv},
Dir: filepath.Join("construct_component_slow", "nodejs"),
Dependencies: []string{"@pulumi/pulumi"},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 5, len(stackInfo.Deployment.Resources)) {
stackRes := stackInfo.Deployment.Resources[0]
assert.NotNil(t, stackRes)
assert.Equal(t, resource.RootStackType, stackRes.Type)
assert.Equal(t, "", string(stackRes.Parent))
}
},
}
integration.ProgramTest(t, opts)
}
func TestGetResourceNode(t *testing.T) {
integration.ProgramTest(t, &integration.ProgramTestOptions{
Dir: filepath.Join("get_resource", "nodejs"),

View file

@ -432,6 +432,42 @@ func TestConstructPython(t *testing.T) {
integration.ProgramTest(t, opts)
}
// Test remote component construction with a child resource that takes a long time to be created, ensuring it's created.
func TestConstructSlowPython(t *testing.T) {
pathEnv, err := testComponentSlowPathEnv()
if err != nil {
t.Fatalf("failed to build test component PATH: %v", err)
}
// TODO[pulumi/pulumi#5455]: Dynamic providers fail to load when used from multi-lang components.
// Until we've addressed this, set PULUMI_TEST_YARN_LINK_PULUMI, which tells the integration test
// module to run `yarn install && yarn link @pulumi/pulumi` in the Python program's directory, allowing
// the Node.js dynamic provider plugin to load.
// When the underlying issue has been fixed, the use of this environment variable inside the integration
// test module should be removed.
const testYarnLinkPulumiEnv = "PULUMI_TEST_YARN_LINK_PULUMI=true"
var opts *integration.ProgramTestOptions
opts = &integration.ProgramTestOptions{
Env: []string{pathEnv, testYarnLinkPulumiEnv},
Dir: filepath.Join("construct_component_slow", "python"),
Dependencies: []string{
filepath.Join("..", "..", "sdk", "python", "env", "src"),
},
Quick: true,
ExtraRuntimeValidation: func(t *testing.T, stackInfo integration.RuntimeValidationStackInfo) {
assert.NotNil(t, stackInfo.Deployment)
if assert.Equal(t, 5, len(stackInfo.Deployment.Resources)) {
stackRes := stackInfo.Deployment.Resources[0]
assert.NotNil(t, stackRes)
assert.Equal(t, resource.RootStackType, stackRes.Type)
assert.Equal(t, "", string(stackRes.Parent))
}
},
}
integration.ProgramTest(t, opts)
}
func TestGetResourcePython(t *testing.T) {
if runtime.GOOS == WindowsOS {
t.Skip("Temporarily skipping test on Windows - pulumi/pulumi#3811")

View file

@ -567,6 +567,15 @@ func TestConfigPaths(t *testing.T) {
//nolint:golint,deadcode
func testComponentPathEnv() (string, error) {
return componentPathEnv("construct_component", "testcomponent")
}
//nolint:golint,deadcode
func testComponentSlowPathEnv() (string, error) {
return componentPathEnv("construct_component_slow", "testcomponent")
}
func componentPathEnv(integrationTest, componentDir string) (string, error) {
cwd, err := os.Getwd()
if err != nil {
return "", err
@ -575,7 +584,7 @@ func testComponentPathEnv() (string, error) {
if err != nil {
return "", err
}
pluginDir := filepath.Join(absCwd, "construct_component", "testcomponent")
pluginDir := filepath.Join(absCwd, integrationTest, componentDir)
pathSeparator := ":"
if runtime.GOOS == "windows" {