fix: replace time.sleep() with checking logs (#899)

Signed-off-by: Lisca Ana-Roberta <ana.kagome@yahoo.com>
This commit is contained in:
Lisca Ana-Roberta
2022-10-21 21:17:06 +03:00
committed by GitHub
parent 00e65bd32b
commit 26d982becb
5 changed files with 139 additions and 6 deletions
+63 -4
View File
@@ -7,6 +7,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"path"
"regexp"
@@ -369,7 +370,18 @@ func TestServerCVEResponseGQL(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func(controller *api.Controller) {
// this blocks
@@ -386,7 +398,11 @@ func TestServerCVEResponseGQL(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
time.Sleep(90 * time.Second)
_, err = test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
if err != nil {
panic(err)
}
defer func(controller *api.Controller) {
ctx := context.Background()
@@ -641,7 +657,18 @@ func TestNegativeServerResponse(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func(controller *api.Controller) {
// this blocks
@@ -658,7 +685,10 @@ func TestNegativeServerResponse(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
time.Sleep(90 * time.Second)
_, err = test.ReadLogFileAndSearchString(logPath, "CVE config not provided, skipping CVE update", 90*time.Second)
if err != nil {
panic(err)
}
defer func(controller *api.Controller) {
ctx := context.Background()
@@ -714,7 +744,18 @@ func TestNegativeServerResponse(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func(controller *api.Controller) {
// this blocks
@@ -731,7 +772,10 @@ func TestNegativeServerResponse(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
time.Sleep(90 * time.Second)
_, err = test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
if err != nil {
panic(err)
}
defer func(controller *api.Controller) {
ctx := context.Background()
@@ -778,7 +822,18 @@ func TestServerCVEResponse(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func(controller *api.Controller) {
// this blocks
@@ -795,7 +850,11 @@ func TestServerCVEResponse(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
time.Sleep(90 * time.Second)
_, err = test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
if err != nil {
panic(err)
}
defer func(controller *api.Controller) {
ctx := context.Background()
+17 -1
View File
@@ -8,6 +8,7 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
"path"
@@ -1269,7 +1270,18 @@ func TestServerResponseGQLWithoutPermissions(t *testing.T) {
Search: searchConfig,
}
logFile, err := os.CreateTemp(t.TempDir(), "zot-log*.txt")
if err != nil {
panic(err)
}
logPath := logFile.Name()
defer os.Remove(logPath)
writers := io.MultiWriter(os.Stdout, logFile)
ctlr := api.NewController(conf)
ctlr.Log.Logger = ctlr.Log.Output(writers)
go func(controller *api.Controller) {
// this blocks
@@ -1286,7 +1298,11 @@ func TestServerResponseGQLWithoutPermissions(t *testing.T) {
time.Sleep(100 * time.Millisecond)
}
time.Sleep(90 * time.Second)
_, err = test.ReadLogFileAndSearchString(logPath, "DB update completed, next update scheduled", 90*time.Second)
if err != nil {
panic(err)
}
defer func(controller *api.Controller) {
err = os.Chmod(path.Join(dir, "zot-test", "blobs"), 0o777)