Skip to content

Commit

Permalink
issue1808: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
DariaFedorova committed Nov 9, 2024
1 parent 5a5bf22 commit a63d042
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,3 +347,52 @@ func TestIsUseStatement(t *testing.T) {
}
}
}

type simpleTestRetryPolycy struct {
retryType RetryType
maxAttempts int
}

func (p *simpleTestRetryPolycy) Attempt(q RetryableQuery) bool {
if q.Attempts() >= p.maxAttempts {
return false
}
return true
}

func (p *simpleTestRetryPolycy) GetRetryType(error) RetryType {
return p.retryType
}

// TestRetryType_Ignore verify that with Ignore retry type:
// - retries stopped
// - return error is nil
// - observed error is not nil
func TestRetryType_Ignore(t *testing.T) {
session := createSession(t)
defer session.Close()

var observedErr error
var observedAttempts int

observer := funcQueryObserver(func(ctx context.Context, o ObservedQuery) {
observedErr = o.Err
observedAttempts++
})

retryPolicy := &simpleTestRetryPolycy{retryType: Ignore, maxAttempts: 2}

err := session.Query("INSERT INTO gocql_test.invalid_table(value) VALUES(1)").Idempotent(true).RetryPolicy(retryPolicy).Observer(observer).Exec()

if err != nil {
t.Fatalf("Expected no error, got: %s", err)
}

if observedErr == nil {
t.Fatalf("Expected unconfigured table error in Obserer, got: nil")
}

if observedAttempts > 1 {
t.Fatal("Expected one attempt")
}
}

0 comments on commit a63d042

Please sign in to comment.