Skip to content

Commit c8b5613

Browse files
fix delete target agent pod at index correction (#2735)
* fix index correction e2e test * style: format code with Gofumpt and Prettier This commit fixes the style issues introduced in 5977085 according to the output from Gofumpt and Prettier. Details: #2735 --------- Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
1 parent 75d03ad commit c8b5613

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

tests/e2e/crud/crud_test.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"fmt"
2626
"os"
2727
"os/exec"
28+
"strings"
2829
"testing"
2930
"time"
3031

@@ -802,8 +803,19 @@ func TestE2EIndexJobCorrection(t *testing.T) {
802803
}
803804

804805
t.Log("Test case 2: execute index correction after one agent removed")
805-
t.Log("removing vald-agent-0...")
806-
cmd := exec.CommandContext(ctx, "sh", "-c", "kubectl delete pod vald-agent-0 && kubectl wait --for=condition=Ready pod/vald-agent-0")
806+
detail, err := op.IndexDetail(t, ctx)
807+
if err != nil {
808+
t.Fatalf("an error occurred: %s", err)
809+
}
810+
var target string
811+
for a, c := range detail.Counts {
812+
if c.Stored > 0 {
813+
target = strings.Split(a, ":")[0]
814+
break
815+
}
816+
}
817+
818+
cmd := exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("kubectl get pods -o custom-columns=:metadata.name --no-headers=true --field-selector=\"status.podIP=%s\"", target))
807819
out, err := cmd.Output()
808820
if err != nil {
809821
if exitErr, ok := err.(*exec.ExitError); ok {
@@ -812,6 +824,18 @@ func TestE2EIndexJobCorrection(t *testing.T) {
812824
t.Fatalf("unexpected error on creating job: %v", err)
813825
}
814826
}
827+
agent := strings.TrimRight(string(out), "\n")
828+
829+
t.Logf("removing %s...", agent)
830+
cmd = exec.CommandContext(ctx, "sh", "-c", fmt.Sprintf("kubectl delete pod %s && kubectl wait --for=condition=Ready pod/%s", agent, agent))
831+
out, err = cmd.Output()
832+
if err != nil {
833+
if exitErr, ok := err.(*exec.ExitError); ok {
834+
t.Fatalf("%s, %s, %v", string(out), string(exitErr.Stderr), err)
835+
} else {
836+
t.Fatalf("unexpected error on creating job: %v", err)
837+
}
838+
}
815839
t.Log(string(out))
816840

817841
// correct the deleted index

tests/e2e/operation/operation.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ type Client interface {
133133
CreateIndex(t *testing.T, ctx context.Context) error
134134
SaveIndex(t *testing.T, ctx context.Context) error
135135
IndexInfo(t *testing.T, ctx context.Context) (*payload.Info_Index_Count, error)
136+
IndexDetail(t *testing.T, ctx context.Context) (*payload.Info_Index_Detail, error)
136137
}
137138

138139
type client struct {
@@ -182,6 +183,15 @@ func (c *client) IndexInfo(t *testing.T, ctx context.Context) (*payload.Info_Ind
182183
return client.IndexInfo(ctx, &payload.Empty{})
183184
}
184185

186+
func (c *client) IndexDetail(t *testing.T, ctx context.Context) (*payload.Info_Index_Detail, error) {
187+
client, err := c.getClient()
188+
if err != nil {
189+
return nil, err
190+
}
191+
192+
return client.IndexDetail(ctx, &payload.Empty{})
193+
}
194+
185195
func (c *client) getGRPCConn() (*grpc.ClientConn, error) {
186196
return grpc.NewClient(
187197
c.host+":"+strconv.Itoa(c.port),

0 commit comments

Comments
 (0)