Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksiienkoMykyta committed Nov 8, 2024
1 parent 92b4056 commit 072a04e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
50 changes: 50 additions & 0 deletions cassandra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"context"
"errors"
"fmt"
"github.com/stretchr/testify/require"
"io"
"math"
"math/big"
Expand Down Expand Up @@ -1042,6 +1043,55 @@ func matchSliceMap(t *testing.T, sliceMap []map[string]interface{}, testMap map[
}
}

type MyRetryPolicy struct {
}

func (*MyRetryPolicy) Attempt(q RetryableQuery) bool {
if q.Attempts() > 5 {
return false
}
return true
}

func (*MyRetryPolicy) GetRetryType(error) RetryType {
return Retry
}

func Test_RetryPolicyIdempotence(t *testing.T) {
session := createSession(t)
defer session.Close()

testCases := []struct {
name string
idempotency bool
expectedNumberOfTries int
}{
{
name: "with retry",
idempotency: true,
expectedNumberOfTries: 6,
},
{
name: "without retry",
idempotency: false,
expectedNumberOfTries: 1,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
q := session.Query("INSERT INTO gocql_test.not_existing_table(event_id, time, args) VALUES (?,?,?)", 4, UUIDFromTime(time.Now()), "test")

q.Idempotent(tc.idempotency)
q.RetryPolicy(&MyRetryPolicy{})
q.Consistency(All)

_ = q.Exec()
require.Equal(t, tc.expectedNumberOfTries, q.Attempts())
})
}
}

func TestSmallInt(t *testing.T) {
session := createSession(t)
defer session.Close()
Expand Down
2 changes: 1 addition & 1 deletion conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestQueryMultinodeWithMetrics(t *testing.T) {
// 1 retry per host
rt := &SimpleRetryPolicy{NumRetries: 3}
observer := &testQueryObserver{metrics: make(map[string]*hostMetrics), verbose: false, logger: log}
qry := db.Query("kill").RetryPolicy(rt).Observer(observer)
qry := db.Query("kill").RetryPolicy(rt).Observer(observer).Idempotent(true)
if err := qry.Exec(); err == nil {
t.Fatalf("expected error")
}
Expand Down

0 comments on commit 072a04e

Please sign in to comment.