Wrote ChannelReadWriter that simulates a connection inmemory. This is used by the agentserver test for testing the initialization. The first test is already working.
34 lines
644 B
Go
34 lines
644 B
Go
package iowrappers
|
|
|
|
import (
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
func SynchronizeStreams(description string, stream1, stream2 io.ReadWriter) {
|
|
waitChannel := make(chan bool, 2)
|
|
|
|
go func() {
|
|
defer func() {
|
|
waitChannel <- true
|
|
}()
|
|
_, err := io.Copy(stream1, stream2)
|
|
if err != nil {
|
|
log.Printf("SynchronizeStreams: %s: error <-: %v\n", description, err)
|
|
}
|
|
}()
|
|
|
|
go func() {
|
|
defer func() {
|
|
waitChannel <- true
|
|
}()
|
|
_, err := io.Copy(stream2, stream1)
|
|
if err != nil {
|
|
log.Printf("SynchronizeStreams: %s: error ->: %v\n", description, err)
|
|
}
|
|
}()
|
|
|
|
<-waitChannel
|
|
log.Printf("SynchronizeStreams: %s: Connection closed", description)
|
|
}
|