Skip to content

Commit

Permalink
fix test server
Browse files Browse the repository at this point in the history
  • Loading branch information
kshvakov committed Sep 2, 2024
1 parent bf81e04 commit 55d0e7d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
2 changes: 0 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/stretchr/testify/assert"
)

const testServerAddr = "127.1.2.1:11211"

func TestAddSet(t *testing.T) {
cache, cancel, err := newTestClient(testServerAddr)
if err != nil {
Expand Down
22 changes: 16 additions & 6 deletions client_utils_test.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package mc_test

import (
"context"
"math/rand"
"net"
"os/exec"
"sync"
"time"

"github.com/kinescope/mc"
)

const testServerAddr = "127.1.2.1:11211"

var letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

func randSeq(n int) string {
Expand Down Expand Up @@ -49,13 +51,19 @@ func newTestServer(addr string) (cancel func(), err error) {
if err != nil {
return nil, err
}
ctx, c := context.WithDeadline(context.Background(), time.Now().Add(time.Second))
defer c()
cmd := exec.CommandContext(ctx, "memcached", "-m", "2", "-p", port, "-l", host)

cmd := exec.Command("memcached", "-m", "2", "-p", port, "-l", host)
if err := cmd.Start(); err != nil {

return nil, err
}
defer cmd.Wait()
var wg sync.WaitGroup
wg.Add(1)
go func() {
wg.Done()
cmd.Wait()
}()
wg.Wait()
for n := range 10 {
c, err := net.DialTimeout("tcp", addr, 500*time.Millisecond)
if err == nil {
Expand All @@ -64,5 +72,7 @@ func newTestServer(addr string) (cancel func(), err error) {
}
time.Sleep(time.Duration(25*n) * time.Millisecond)
}
return func() { cmd.Process.Kill() }, nil
return func() {
cmd.Process.Kill()
}, nil
}

0 comments on commit 55d0e7d

Please sign in to comment.