Skip to content

Commit 3d65a39

Browse files
committed
Remove inconsistent test
The TestCreateLogFilesHandler has been deleted since there are other tests that test the individual parts of the handler. The handler itself is asynchronous which causes some inconsistencies when testing against the handler itself. Signed-off-by: xibz <[email protected]>
1 parent 9ad278f commit 3d65a39

File tree

1 file changed

+0
-91
lines changed

1 file changed

+0
-91
lines changed

handlers_test.go

Lines changed: 0 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
package firecracker
22

33
import (
4-
"bytes"
54
"context"
65
"fmt"
76
"os"
87
"path/filepath"
98
"reflect"
109
"testing"
11-
"time"
1210

1311
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
1412
ops "github.com/firecracker-microvm/firecracker-go-sdk/client/operations"
1513
"github.com/firecracker-microvm/firecracker-go-sdk/fctesting"
16-
"github.com/pkg/errors"
1714
)
1815

1916
func TestHandlerListAppend(t *testing.T) {
@@ -663,76 +660,6 @@ func TestHandlers(t *testing.T) {
663660
}
664661
}
665662

666-
func TestCreateLogFilesHandler(t *testing.T) {
667-
logWriterBuf := &bytes.Buffer{}
668-
config := Config{
669-
LogFifo: filepath.Join(testDataPath, "firecracker-log.fifo"),
670-
MetricsFifo: filepath.Join(testDataPath, "firecracker-metrics.fifo"),
671-
FifoLogWriter: logWriterBuf,
672-
}
673-
674-
defer func() {
675-
os.Remove(config.LogFifo)
676-
os.Remove(config.MetricsFifo)
677-
}()
678-
679-
ctx := context.Background()
680-
m, err := NewMachine(ctx, config, WithLogger(fctesting.NewLogEntry(t)))
681-
if err != nil {
682-
t.Fatalf("failed to create machine: %v", err)
683-
}
684-
685-
// spin off goroutine to write to Log fifo so we don't block
686-
doneChan := make(chan struct{}, 1)
687-
go func() {
688-
defer close(doneChan)
689-
690-
// try to open file
691-
fifoPipe, err := openFileRetry(config.LogFifo)
692-
if err != nil {
693-
t.Error(err)
694-
}
695-
696-
if _, err := fifoPipe.WriteString("data\n"); err != nil {
697-
t.Errorf("Failed to write to fifo %v", err)
698-
}
699-
700-
fifoPipe.Close()
701-
return
702-
}()
703-
704-
// Execute Handler
705-
if err := CreateLogFilesHandler.Fn(ctx, m); err != nil {
706-
t.Errorf("failed to call CreateLogFilesHandler function: %v", err)
707-
return
708-
}
709-
710-
// Block until writing go routine is done to check data that was written
711-
<-doneChan
712-
713-
// Poll for verifying logs were written as we need to allow time
714-
// for copying from the log fifo into the FifoLogWriter
715-
timer := time.NewTimer(1 * time.Second)
716-
for {
717-
select {
718-
case <-timer.C:
719-
t.Fatal("timed out reading from log writer")
720-
default:
721-
logData, err := logWriterBuf.ReadString('\n')
722-
if err != nil {
723-
time.Sleep(10 * time.Millisecond)
724-
continue
725-
}
726-
727-
if logData != "data\n" {
728-
t.Errorf("expected 'data' written to log got '%s'", logData)
729-
}
730-
return
731-
}
732-
}
733-
734-
}
735-
736663
func compareHandlerLists(l1, l2 HandlerList) bool {
737664
if l1.Len() != l2.Len() {
738665
return false
@@ -754,21 +681,3 @@ func compareHandlerLists(l1, l2 HandlerList) bool {
754681

755682
return true
756683
}
757-
758-
func openFileRetry(filePath string) (file *os.File, err error) {
759-
timer := time.NewTimer(1 * time.Second)
760-
for {
761-
select {
762-
case <-timer.C:
763-
err = errors.New("timed out waiting for file")
764-
return
765-
default:
766-
file, err = os.OpenFile(filePath, os.O_WRONLY, os.ModePerm)
767-
if err == nil {
768-
timer.Stop()
769-
return
770-
}
771-
time.Sleep(10 * time.Millisecond)
772-
}
773-
}
774-
}

0 commit comments

Comments
 (0)