10000 fix(e2e): treat corner cases in ds_writer.go by geyslan · Pull Request #4554 · aquasecurity/tracee · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(e2e): treat corner cases in ds_writer.go #4554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
29 changes: 23 additions & 6 deletions tests/e2e-inst-signatures/scripts/ds_writer/ds_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ package main

import (
"context"
"errors"
"flag"
"fmt"
"io"
"math/rand"
"os"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
Expand All @@ -23,8 +26,8 @@ func chooseWord(list []string) string {
return list[rand.Intn(len(list))]
}

func contaminate(client v1beta1.DataSourceServiceClient) error {
stream, err := client.WriteStream(context.Background())
func contaminate(ctx context.Context, client v1beta1.DataSourceServiceClient) error {
stream, err := client.WriteStream(ctx)
if err != nil {
return fmt.Errorf("error establishing stream: %v", err)
}
Expand All @@ -38,6 +41,10 @@ func contaminate(client v1beta1.DataSourceServiceClient) error {
Value: structpb.NewStringValue(randomValue),
})
if err != nil {
if errors.Is(err, io.EOF) {
break
}

return err
}
}
Expand Down Expand Up @@ -70,16 +77,26 @@ func main() {
if err != nil {
printAndExit("failed to dial tracee grpc server: %v\n", err)
}
defer func() {
err := conn.Close()
if err != nil {
printAndExit("failed to close connection: %v\n", err)
}
}()

ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

client := v1beta1.NewDataSourceServiceClient(conn)
err = contaminate(client)
err = contaminate(ctx, client)
if err != nil {
printAndExit("error contaminating data source: %v\n", err)
}
_, err = client.Write(context.Background(), &v1beta1.WriteDataSourceRequest{
_, err = client.Write(ctx, &v1beta1.WriteDataSourceRequest{
Id: "demo",
Namespace: "e2e_inst",
Key: structpb.NewStringValue("bruh"),
Value: structpb.NewStringValue("moment"),
Key: structpb.NewStringValue(key),
Value: structpb.NewStringValue(value),
})

if err != nil {
Expand Down
Loading
0