Skip to content

Commit

Permalink
fix(legacy): remove flaky test
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Guerra <luca@guerra.sh>
  • Loading branch information
LucaGuerra authored and poiana committed Nov 6, 2024
1 parent 1bcaa30 commit bcd1f4a
Showing 1 changed file with 0 additions and 74 deletions.
74 changes: 0 additions & 74 deletions tests/falco/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,11 @@ package testfalco
import (
"bufio"
"bytes"
"context"
"errors"
"os"
"strings"
"sync"
"testing"
"time"

grpcOutputs "github.com/falcosecurity/client-go/pkg/api/outputs"
"github.com/falcosecurity/client-go/pkg/client"

"github.com/falcosecurity/testing/pkg/falco"
"github.com/falcosecurity/testing/pkg/run"
Expand Down Expand Up @@ -2908,75 +2903,6 @@ func grpcOutputResponseToFalcoAlert(res *grpcOutputs.Response) *falco.Alert {
}
}

func TestFalco_Legacy_GrpcUnixSocketOutputs(t *testing.T) {
var wg sync.WaitGroup
defer wg.Wait()
t.Parallel()

// launch falco asynchronously
ctx, ctxCancel := context.WithCancel(context.Background())
defer ctxCancel()
runner := tests.NewFalcoExecutableRunner(t)
socketName := runner.WorkDir() + "/falco.sock"
wg.Add(1)
go func() {
defer wg.Done()
res := falco.Test(
runner,
falco.WithContext(ctx),
falco.WithRules(rules.SingleRuleWithTags),
falco.WithConfig(configs.GrpcUnixSocket),
falco.WithCaptureFile(captures.CatWrite),
falco.WithStopAfter(30*time.Second),
falco.WithArgs("-o", "time_format_iso_8601=true"),
falco.WithArgs("-o", "grpc.bind_address=unix://"+socketName),
)
require.NotContains(t, res.Stderr(), "Error starting gRPC server")
// todo(jasondellaluce): skipping this as it can be flaky (Falco sometimes shuts down
// with exit code -1), we need to investigate on that
// require.Nil(t, res.Err())
}()

// wait up until Falco creates the unix socket
socketCreated := false
for i := 0; i < 50; i++ {
if _, err := os.Stat(socketName); err != nil {
time.Sleep(100 * time.Millisecond)
continue
}
socketCreated = true
break
}

assert.Truef(t, socketCreated, "The socket %s was not created successfully in the allotted time", socketName)

// connect using the Falco grpc client and collect detection
grpcClient, err := client.NewForConfig(ctx, &client.Config{UnixSocketPath: "unix://" + socketName})
require.Nil(t, err)

expectedCount := 8
expectedErr := errors.New("expected error")
detections := make(falco.Detections, 0)
err = grpcClient.OutputsWatch(context.Background(), func(res *grpcOutputs.Response) error {
detections = append(detections, grpcOutputResponseToFalcoAlert(res))
if len(detections) == expectedCount {
// note: we stop Falco when we reache the number of expected
// detections
ctxCancel()
return expectedErr
}
return nil
}, 100*time.Millisecond)

// perform checks on the detections
// todo(jasondellaluce): add deeper checks on the received struct
require.Equal(t, expectedErr.Error(), err.Error())
assert.Equal(t, expectedCount, detections.Count())
assert.Equal(t, expectedCount, detections.
OfPriority("WARNING").
OfRule("open_from_cat").Count())
}

func TestFalco_Legacy_NoPluginsUnknownSource(t *testing.T) {
t.Parallel()
checkConfig(t)
Expand Down

0 comments on commit bcd1f4a

Please sign in to comment.