WIP test but i think im done
This commit is contained in:
@@ -149,9 +149,10 @@ func (c Config) WithConn(hashKey string, foo func(net.Conn) error) error {
|
|||||||
log.Printf("errored with conn %v: %v", hashIdx, err)
|
log.Printf("errored with conn %v: %v", hashIdx, err)
|
||||||
forwardConn.Close()
|
forwardConn.Close()
|
||||||
return err
|
return err
|
||||||
}
|
} else {
|
||||||
|
|
||||||
log.Printf("release conn %v", hashIdx)
|
log.Printf("release conn %v", hashIdx)
|
||||||
forward.Put(forwardConn)
|
forward.Put(forwardConn)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
54
src/listen_test.go
Normal file
54
src/listen_test.go
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
package src
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"encoding/base64"
|
||||||
|
"net/http"
|
||||||
|
"net/http/httptest"
|
||||||
|
"strings"
|
||||||
|
"sync"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestListenLifecycle(t *testing.T) {
|
||||||
|
ctx, can := context.WithTimeout(context.Background(), time.Second*5)
|
||||||
|
defer can()
|
||||||
|
|
||||||
|
valkeyPort := getPort(t)
|
||||||
|
valkeyReady := make(chan struct{})
|
||||||
|
valkeyReadyCloserOnce := &sync.Once{}
|
||||||
|
go func() {
|
||||||
|
defer close(valkeyReady)
|
||||||
|
t.Fatal("not impl: start pretend valkey server")
|
||||||
|
}()
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
case <-valkeyReady:
|
||||||
|
}
|
||||||
|
|
||||||
|
config := Config{
|
||||||
|
ctx: ctx,
|
||||||
|
Listen: ":" + getPort(t),
|
||||||
|
Forwards: "127.0.0.1:" + valkeyPort,
|
||||||
|
Hello: base64.StdEncoding.EncodeToString([]byte("+ping\r\n")),
|
||||||
|
}
|
||||||
|
if err := config.setForwards(); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer can()
|
||||||
|
t.Fatal("not impl: dial listen")
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := listen(ctx, config); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getPort(t *testing.T) string {
|
||||||
|
s := httptest.NewServer(http.HandlerFunc(http.NotFound))
|
||||||
|
s.Close()
|
||||||
|
return strings.Split(s.URL, ":")[2]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user