v1.5.1 增强程序稳定性
This commit is contained in:
27
EdgeNode/internal/utils/kvstore/tx_internal_test.go
Normal file
27
EdgeNode/internal/utils/kvstore/tx_internal_test.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package kvstore
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/cockroachdb/pebble"
|
||||
)
|
||||
|
||||
func TestTx_commit_StringPanicReturnsError(t *testing.T) {
|
||||
oldCommitBatch := commitBatch
|
||||
commitBatch = func(batch *pebble.Batch, opt *pebble.WriteOptions) error {
|
||||
panic("boom")
|
||||
}
|
||||
defer func() {
|
||||
commitBatch = oldCommitBatch
|
||||
}()
|
||||
|
||||
tx := &Tx[string]{}
|
||||
err := tx.commit(DefaultWriteOptions)
|
||||
if err == nil {
|
||||
t.Fatal("expected error, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "commit batch failed: boom") {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user