Skip to content

Commit

Permalink
test: fix problems of integration test binary mode impl (#814)
Browse files Browse the repository at this point in the history
Signed-off-by: spacewander <[email protected]>
  • Loading branch information
spacewander authored Dec 6, 2024
1 parent ba4d8a7 commit 2e9de01
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
11 changes: 7 additions & 4 deletions api/plugins/tests/integration/dataplane/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
31 changes: 27 additions & 4 deletions api/plugins/tests/integration/dataplane/data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"runtime"
"strconv"
"strings"
"sync"
"syscall"
"testing"
"time"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 2e9de01

Please sign in to comment.