core: Fix TestContext2Apply_moduleDestroyOrder

This test was occasionally failing due to a missing graph edge causing it
to be non-deterministic.

The graph edge was missing because our standard schema doesn't quite match
the config fixture and so the reference checker was not finding the "blah"
argument on aws_instance.a.

This change also includes an 100ms pause for the b node just to make this
potential race more likely to hit the "wrong" ordering when the graph is
not complete.
This commit is contained in:
Martin Atkins 2018-09-28 14:54:38 -07:00
parent cbac51a470
commit 55103985f7
3 changed files with 25 additions and 3 deletions

View File

@ -2583,6 +2583,13 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
info *InstanceInfo,
is *InstanceState,
id *InstanceDiff) (*InstanceState, error) {
if is.ID == "b" {
// Pause briefly to make any race conditions more visible, since
// missing edges here can cause undeterministic ordering.
time.Sleep(100 * time.Millisecond)
}
orderLock.Lock()
defer orderLock.Unlock()
@ -2590,6 +2597,18 @@ func TestContext2Apply_moduleDestroyOrder(t *testing.T) {
return nil, nil
}
p.GetSchemaReturn = &ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
"aws_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Required: true},
"blah": {Type: cty.String, Optional: true},
"value": {Type: cty.String, Optional: true},
},
},
},
}
state := mustShimLegacyState(&State{
Modules: []*ModuleState{
&ModuleState{

View File

@ -1,4 +1,6 @@
resource "aws_instance" "a" {}
resource "aws_instance" "a" {
id = "a"
}
output "a_output" {
value = "${aws_instance.a.id}"

View File

@ -3,5 +3,6 @@ module "child" {
}
resource "aws_instance" "b" {
id = "b"
blah = "${module.child.a_output}"
}