From 60356247c767fd5f6dfe278189b3f601d3ea7168 Mon Sep 17 00:00:00 2001 From: Dave Shanley Date: Sat, 20 Apr 2024 14:15:20 -0400 Subject: [PATCH] Fixed issue with race conditions in test further up the stack. --- schema_validation/locate_schema_property.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/schema_validation/locate_schema_property.go b/schema_validation/locate_schema_property.go index 167c473..8fbcef5 100644 --- a/schema_validation/locate_schema_property.go +++ b/schema_validation/locate_schema_property.go @@ -14,6 +14,7 @@ import ( func LocateSchemaPropertyNodeByJSONPath(doc *yaml.Node, JSONPath string) *yaml.Node { var locatedNode *yaml.Node doneChan := make(chan bool) + locatedNodeChan := make(chan *yaml.Node) go func() { defer func() { if err := recover(); err != nil { @@ -30,8 +31,12 @@ func LocateSchemaPropertyNodeByJSONPath(doc *yaml.Node, JSONPath string) *yaml.N if len(locatedNodes) > 0 { locatedNode = locatedNodes[0] } - doneChan <- true + locatedNodeChan <- locatedNode }() - <-doneChan - return locatedNode + select { + case locatedNode = <-locatedNodeChan: + return locatedNode + case <-doneChan: + return nil + } }