From 47529f829efbb93789a4a1d8ac493701fbc046cc Mon Sep 17 00:00:00 2001 From: Carlos Diaz-Padron Date: Mon, 28 Jul 2014 13:51:13 -0700 Subject: [PATCH] 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 dd20e8ac03..de7b2c8247 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 e3f604635e..835d652a9c 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