From 47529f829efbb93789a4a1d8ac493701fbc046cc Mon Sep 17 00:00:00 2001 From: Carlos Diaz-Padron Date: Mon, 28 Jul 2014 13:51:13 -0700 Subject: [PATCH 1/2] Fix maps race in append and merge tests --- config/append.go | 15 ++++++++++----- config/merge.go | 15 ++++++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/config/append.go b/config/append.go index dd20e8ac0..de7b2c824 100644 --- a/config/append.go +++ b/config/append.go @@ -15,13 +15,18 @@ func Append(c1, c2 *Config) (*Config, error) { // Append unknown keys, but keep them unique since it is a set unknowns := make(map[string]struct{}) for _, k := range c1.unknownKeys { - unknowns[k] = struct{}{} + _, present := unknowns[k] + if !present { + unknowns[k] = struct{}{} + c.unknownKeys = append(c.unknownKeys, k) + } } for _, k := range c2.unknownKeys { - unknowns[k] = struct{}{} - } - for k, _ := range unknowns { - c.unknownKeys = append(c.unknownKeys, k) + _, present := unknowns[k] + if !present { + unknowns[k] = struct{}{} + c.unknownKeys = append(c.unknownKeys, k) + } } if len(c1.Outputs) > 0 || len(c2.Outputs) > 0 { diff --git a/config/merge.go b/config/merge.go index e3f604635..835d652a9 100644 --- a/config/merge.go +++ b/config/merge.go @@ -11,13 +11,18 @@ func Merge(c1, c2 *Config) (*Config, error) { // Merge unknown keys unknowns := make(map[string]struct{}) for _, k := range c1.unknownKeys { - unknowns[k] = struct{}{} + _, present := unknowns[k] + if !present { + unknowns[k] = struct{}{} + c.unknownKeys = append(c.unknownKeys, k) + } } for _, k := range c2.unknownKeys { - unknowns[k] = struct{}{} - } - for k, _ := range unknowns { - c.unknownKeys = append(c.unknownKeys, k) + _, present := unknowns[k] + if !present { + unknowns[k] = struct{}{} + c.unknownKeys = append(c.unknownKeys, k) + } } // NOTE: Everything below is pretty gross. Due to the lack of generics From d66c9f883fd36e007944b71650646d083e1d9db8 Mon Sep 17 00:00:00 2001 From: Carlos Diaz-Padron Date: Tue, 29 Jul 2014 10:26:50 -0700 Subject: [PATCH 2/2] Fix TestWriteDot random order error --- digraph/graphviz_test.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/digraph/graphviz_test.go b/digraph/graphviz_test.go index fce1ebb6f..69e4ebb89 100644 --- a/digraph/graphviz_test.go +++ b/digraph/graphviz_test.go @@ -24,7 +24,27 @@ b -> e actual := strings.TrimSpace(string(buf.Bytes())) expected := strings.TrimSpace(writeDotStr) - if actual != expected { + + actualLines := strings.Split(actual, "\n") + expectedLines := strings.Split(expected, "\n") + + if actualLines[0] != expectedLines[0] || + actualLines[len(actualLines)-1] != expectedLines[len(expectedLines)-1] || + len(actualLines) != len(expectedLines) { + t.Fatalf("bad: %s", actual) + } + + count := 0 + for _, el := range expectedLines[1 : len(expectedLines)-1] { + for _, al := range actualLines[1 : len(actualLines)-1] { + if el == al { + count++ + break + } + } + } + + if count != len(expectedLines)-2 { t.Fatalf("bad: %s", actual) } }