Update tests to properly use IsServing
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
7de9ca519c
commit
fed5ad4bc5
@ -11,6 +11,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"google.golang.org/grpc/grpclog"
|
"google.golang.org/grpc/grpclog"
|
||||||
|
|
||||||
@ -73,18 +74,20 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := ctrd.waitForStart(ctx)
|
waitCtx, waitCancel := context.WithTimeout(ctx, 2*time.Second)
|
||||||
|
client, err := ctrd.waitForStart(waitCtx)
|
||||||
|
waitCancel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctrd.Kill()
|
ctrd.Kill()
|
||||||
ctrd.Wait()
|
ctrd.Wait()
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s", err, buf.String())
|
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// print out the version in information
|
// print out the version in information
|
||||||
version, err := client.Version(ctx)
|
version, err := client.Version(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "error getting version: %s", err)
|
fmt.Fprintf(os.Stderr, "error getting version: %s\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +102,7 @@ func TestMain(m *testing.M) {
|
|||||||
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
|
if _, err = client.Pull(ctx, testImage, WithPullUnpack); err != nil {
|
||||||
ctrd.Stop()
|
ctrd.Stop()
|
||||||
ctrd.Wait()
|
ctrd.Wait()
|
||||||
fmt.Fprintf(os.Stderr, "%s: %s", err, buf.String())
|
fmt.Fprintf(os.Stderr, "%s: %s\n", err, buf.String())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -240,14 +240,9 @@ func TestDaemonRestart(t *testing.T) {
|
|||||||
|
|
||||||
<-statusC
|
<-statusC
|
||||||
|
|
||||||
serving := false
|
waitCtx, waitCancel := context.WithTimeout(ctx, 2*time.Second)
|
||||||
for i := 0; i < 20; i++ {
|
serving, err := client.IsServing(waitCtx)
|
||||||
serving, err = client.IsServing(ctx)
|
waitCancel()
|
||||||
if serving {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
if !serving {
|
if !serving {
|
||||||
t.Fatalf("containerd did not start within 2s: %v", err)
|
t.Fatalf("containerd did not start within 2s: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,6 @@ package containerd
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"sync"
|
"sync"
|
||||||
@ -44,19 +43,19 @@ func (d *daemon) waitForStart(ctx context.Context) (*Client, error) {
|
|||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
|
||||||
for i := 0; i < 20; i++ {
|
client, err = New(address)
|
||||||
if client == nil {
|
if err != nil {
|
||||||
client, err = New(d.addr)
|
return nil, err
|
||||||
}
|
}
|
||||||
if err == nil {
|
|
||||||
serving, err = client.IsServing(ctx)
|
serving, err = client.IsServing(ctx)
|
||||||
if serving {
|
if !serving {
|
||||||
return client, nil
|
client.Close()
|
||||||
|
if err == nil {
|
||||||
|
err = errors.New("connection was successful but service is not available")
|
||||||
}
|
}
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Millisecond)
|
return client, err
|
||||||
}
|
|
||||||
return nil, fmt.Errorf("containerd did not start within 2s: %v", err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *daemon) Stop() error {
|
func (d *daemon) Stop() error {
|
||||||
|
Loading…
Reference in New Issue
Block a user