diff --git a/api/plugins/tests/integration/dataplane/bootstrap.go b/api/plugins/tests/integration/dataplane/bootstrap.go index 5c999145..9fe22e57 100644 --- a/api/plugins/tests/integration/dataplane/bootstrap.go +++ b/api/plugins/tests/integration/dataplane/bootstrap.go @@ -166,10 +166,6 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) { if c.(map[string]interface{})["name"] == "config_server" { load := c.(map[string]interface{})["load_assignment"].(map[string]interface{})["endpoints"].([]interface{})[0].(map[string]interface{})["lb_endpoints"].([]interface{})[0].(map[string]interface{})["endpoint"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{}) load["port_value"] = port - - if isBinaryMode() { - load["address"] = "0.0.0.0" - } break } } @@ -197,6 +193,13 @@ func (b *bootstrap) buildConfiguration() (map[string]interface{}, error) { } } } + + for _, c := range staticResources["clusters"].([]interface{}) { + load := c.(map[string]interface{})["load_assignment"].(map[string]interface{})["endpoints"].([]interface{})[0].(map[string]interface{})["lb_endpoints"].([]interface{})[0].(map[string]interface{})["endpoint"].(map[string]interface{})["address"].(map[string]interface{})["socket_address"].(map[string]interface{}) + if load["address"] == "host.docker.internal" { + load["address"] = "0.0.0.0" + } + } } return root, nil diff --git a/api/plugins/tests/integration/dataplane/data_plane.go b/api/plugins/tests/integration/dataplane/data_plane.go index bf7ea9d2..4e29b0e0 100644 --- a/api/plugins/tests/integration/dataplane/data_plane.go +++ b/api/plugins/tests/integration/dataplane/data_plane.go @@ -32,6 +32,7 @@ import ( "runtime" "strconv" "strings" + "sync" "syscall" "testing" "time" @@ -80,6 +81,22 @@ func addEnvironemntVariables(cmd *exec.Cmd, envs map[string]string) { } } +type serializableFileWriter struct { + *os.File + + lock sync.Mutex +} + +func (w *serializableFileWriter) Write(p []byte) (n int, err error) { + w.lock.Lock() + defer w.lock.Unlock() + return w.File.Write(p) +} + +func (w *serializableFileWriter) Unbox() *os.File { + return w.File +} + func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) { if opt == nil { opt = &Option{} @@ -295,15 +312,18 @@ func StartDataPlane(t *testing.T, opt *Option) (*DataPlane, error) { if err != nil { return nil, err } - cmd.Stdout = stdout + + // wrap writer to ensure the stderr and stdout won't affect each other + w := &serializableFileWriter{File: stdout} + cmd.Stdout = w // We don't need stderr file, which is used to store docker output in the standard mode. - cmd.Stderr = stdout // Just left an empty file here to keep the same structure. _, err = os.Create(filepath.Join(dir, "stderr")) if err != nil { return nil, err } + cmd.Stderr = w } else { stdout, err := os.Create(filepath.Join(dir, "stdout")) if err != nil { @@ -409,12 +429,15 @@ func (dp *DataPlane) Stop() { <-dp.done logger.Info("envoy stopped") + var f *os.File if !isBinaryMode() { - f := dp.cmd.Stderr.(*os.File) + f = dp.cmd.Stderr.(*os.File) f.Close() + f = dp.cmd.Stdout.(*os.File) + } else { + f = dp.cmd.Stdout.(*serializableFileWriter).Unbox() } - f := dp.cmd.Stdout.(*os.File) f.Seek(0, 0) text, err := io.ReadAll(f) defer f.Close()