Skip to content

Commit

Permalink
Feedback #9
Browse files Browse the repository at this point in the history
  • Loading branch information
lukedirtwalker committed Jul 31, 2018
1 parent 254abfc commit 27ed805
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 5 additions & 1 deletion go/examples/pingpong/pingpong.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/lucas-clemente/quic-go/qerr"

"github.com/scionproto/scion/go/lib/common"
"github.com/scionproto/scion/go/lib/integration"
"github.com/scionproto/scion/go/lib/log"
sd "github.com/scionproto/scion/go/lib/sciond"
"github.com/scionproto/scion/go/lib/snet"
Expand Down Expand Up @@ -346,7 +347,10 @@ func (s server) run() {
if err != nil {
LogFatal("Unable to listen", "err", err)
}
fmt.Printf("Listening ia=%s\n", local.IA) // Needed for integration test ready signal.
if len(os.Getenv(integration.GoIntegrationEnv)) > 0 {
// Needed for integration test ready signal.
fmt.Printf("%s%s\n", integration.ReadySignal, local.IA)
}
log.Info("Listening", "local", qsock.Addr())
for {
qsess, err := qsock.Accept()
Expand Down
17 changes: 11 additions & 6 deletions go/lib/integration/binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ const (
// The message should always be `Listening ia=<IA>`
// where <IA> is the IA the server is listening on.
ReadySignal = "Listening ia="
// GoIntegrationEnv is an environment variable that is set for the binary under test.
// It can be used to guard certain statements, like printing the ReadySignal,
// in a program under test.
GoIntegrationEnv = "SCION_GO_INTEGRATION"
)

var _ Integration = (*binaryIntegration)(nil)
Expand Down Expand Up @@ -69,6 +73,7 @@ func (bi *binaryIntegration) StartServer(ctx context.Context, dst addr.IA) (Wait
r := &binaryWaiter{
exec.CommandContext(ctx, bi.name, args...),
}
r.Env = append(r.Env, fmt.Sprintf("%s=1", GoIntegrationEnv))
ep, err := r.StderrPipe()
if err != nil {
return nil, err
Expand All @@ -79,15 +84,18 @@ func (bi *binaryIntegration) StartServer(ctx context.Context, dst addr.IA) (Wait
}
ready := make(chan struct{})
// parse until we have the ready signal.
// and then discard the output until the end (required by StdoutPipe).
go func() {
defer log.LogPanicAndExit()
defer sp.Close()
signal := fmt.Sprintf("%s%s", ReadySignal, dst)
init := true
scanner := bufio.NewScanner(sp)
for scanner.Scan() {
line := scanner.Text()
if fmt.Sprintf("%s%s", ReadySignal, dst) == line {
if init && signal == line {
close(ready)
return
init = false
}
}
}()
Expand All @@ -110,6 +118,7 @@ func (bi *binaryIntegration) StartClient(ctx context.Context, src, dst addr.IA)
r := &binaryWaiter{
exec.CommandContext(ctx, bi.name, args...),
}
r.Env = append(r.Env, fmt.Sprintf("%s=1", GoIntegrationEnv))
ep, err := r.StderrPipe()
if err != nil {
return nil, err
Expand Down Expand Up @@ -137,10 +146,6 @@ func redirectLog(name, pName string, local addr.IA, ep io.ReadCloser) {
})
}

func readyConsumer(local addr.IA) {

}

var _ Waiter = (*binaryWaiter)(nil)

type binaryWaiter struct {
Expand Down

0 comments on commit 27ed805

Please sign in to comment.