Revert commitse5330641and0df41523which removed embedded Dolt mode from the beads codebase. The embedded Dolt removal was only intended for Gas Town, not for Beads. Restores: - dolthub/driver dependency and embedded connection path - Advisory flock (AccessLock) for concurrent process protection - Embedded connector lifecycle management in DoltStore - All CGO build tags across ~45 files - Vendored go-icu-regex library - nocgo stub files for non-CGO builds - Bootstrap and embedded_uow helpers - factory_dolt_test.go and dolt_singleprocess_test.go Merge conflict resolutions: - store.go: TCP fail-fast check wrapped inside if cfg.ServerMode - store.go: backtick-quoting for embedded CREATE DATABASE (prefix-based names) - perf_dolt.go: port references updated from 3306 to 3307 - ci.yml: restored continue-on-error for Nix (dolthub/driver requires Go 1.25.6+) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Executed-By: beads/crew/emma Rig: beads Role: crew
143 lines
3.1 KiB
Go
143 lines
3.1 KiB
Go
//go:build cgo
|
|
package dolt
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"testing"
|
|
)
|
|
|
|
func TestIsRetryableError(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
err error
|
|
expected bool
|
|
}{
|
|
{
|
|
name: "nil error",
|
|
err: nil,
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "driver bad connection",
|
|
err: errors.New("driver: bad connection"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "Driver Bad Connection (case insensitive)",
|
|
err: errors.New("Driver: Bad Connection"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "invalid connection",
|
|
err: errors.New("invalid connection"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "broken pipe",
|
|
err: errors.New("write: broken pipe"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "connection reset",
|
|
err: errors.New("read: connection reset by peer"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "connection refused - retryable (server restart)",
|
|
err: errors.New("dial tcp: connection refused"),
|
|
expected: true,
|
|
},
|
|
{
|
|
name: "syntax error - not retryable",
|
|
err: errors.New("Error 1064: You have an error in your SQL syntax"),
|
|
expected: false,
|
|
},
|
|
{
|
|
name: "table not found - not retryable",
|
|
err: errors.New("Error 1146: Table 'beads.foo' doesn't exist"),
|
|
expected: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
got := isRetryableError(tt.err)
|
|
if got != tt.expected {
|
|
t.Errorf("isRetryableError(%v) = %v, want %v", tt.err, got, tt.expected)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestWithRetry_EmbeddedMode(t *testing.T) {
|
|
// In embedded mode (serverMode=false), withRetry should just call the operation once
|
|
store := &DoltStore{serverMode: false}
|
|
|
|
callCount := 0
|
|
err := store.withRetry(context.Background(), func() error {
|
|
callCount++
|
|
return errors.New("driver: bad connection")
|
|
})
|
|
|
|
if err == nil {
|
|
t.Error("expected error, got nil")
|
|
}
|
|
if callCount != 1 {
|
|
t.Errorf("expected 1 call in embedded mode, got %d", callCount)
|
|
}
|
|
}
|
|
|
|
func TestWithRetry_ServerMode_Success(t *testing.T) {
|
|
store := &DoltStore{serverMode: true}
|
|
|
|
callCount := 0
|
|
err := store.withRetry(context.Background(), func() error {
|
|
callCount++
|
|
return nil
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
if callCount != 1 {
|
|
t.Errorf("expected 1 call on success, got %d", callCount)
|
|
}
|
|
}
|
|
|
|
func TestWithRetry_ServerMode_RetryOnBadConnection(t *testing.T) {
|
|
store := &DoltStore{serverMode: true}
|
|
|
|
callCount := 0
|
|
err := store.withRetry(context.Background(), func() error {
|
|
callCount++
|
|
if callCount < 3 {
|
|
return errors.New("driver: bad connection")
|
|
}
|
|
return nil // Success on 3rd attempt
|
|
})
|
|
|
|
if err != nil {
|
|
t.Errorf("unexpected error: %v", err)
|
|
}
|
|
if callCount != 3 {
|
|
t.Errorf("expected 3 calls (2 retries + success), got %d", callCount)
|
|
}
|
|
}
|
|
|
|
func TestWithRetry_ServerMode_NonRetryableError(t *testing.T) {
|
|
store := &DoltStore{serverMode: true}
|
|
|
|
callCount := 0
|
|
err := store.withRetry(context.Background(), func() error {
|
|
callCount++
|
|
return errors.New("syntax error in SQL")
|
|
})
|
|
|
|
if err == nil {
|
|
t.Error("expected error, got nil")
|
|
}
|
|
if callCount != 1 {
|
|
t.Errorf("expected 1 call for non-retryable error, got %d", callCount)
|
|
}
|
|
}
|