MCPcopy
hub / github.com/pingcap/tidb / RunTestStorage

Function RunTestStorage

br/pkg/task/operator/test_storage.go:225–309  ·  view source on GitHub ↗

RunTestStorage tests all operations of an external storage.

(ctx context.Context, cfg TestStorageConfig)

Source from the content-addressed store, hash-verified

223
224// RunTestStorage tests all operations of an external storage.
225func RunTestStorage(ctx context.Context, cfg TestStorageConfig) error {
226 logger := logutil.Logger(ctx)
227 logger.Info("Starting external storage test", zap.String("storage", cfg.StorageURI), zap.Any("options", cfg.BackendOptions))
228
229 // Initialize test report
230 report := &TestReport{
231 StorageURI: cfg.StorageURI,
232 StartTime: time.Now(),
233 TestResults: make([]TestResult, 0),
234 }
235
236 // Parse and create storage
237 backend, err := storage.ParseBackend(cfg.StorageURI, &cfg.BackendOptions)
238 if err != nil {
239 return errors.Annotate(err, "failed to parse storage backend")
240 }
241
242 store, err := storage.New(ctx, backend, &storage.ExternalStorageOptions{
243 SendCredentials: true,
244 })
245 if err != nil {
246 return errors.Annotate(err, "failed to create external storage")
247 }
248 defer store.Close()
249
250 printStep("Testing external storage: %s", store.URI())
251 report.StorageURI = store.URI()
252
253 // Create test context
254 tc := &TestContext{
255 Ctx: ctx,
256 Report: report,
257 Store: store,
258 PauseWhenFail: cfg.PauseWhenFail,
259 }
260
261 // Generate test data
262 testData := make([]byte, cfg.TestDataSize)
263 if _, err := rand.Read(testData); err != nil {
264 return errors.Annotate(err, "failed to generate test data")
265 }
266 printStep("Generated test data: %s", formatBytes(cfg.TestDataSize))
267
268 cleanup := func() {
269 if !cfg.CleanupOnSuccess {
270 return
271 }
272 printStep("Cleaning up test files...")
273 _ = store.DeleteFile(ctx, testFileName1)
274 _ = store.DeleteFile(ctx, testFileName2)
275 _ = store.DeleteFile(ctx, testFileNameRenamed)
276 _ = store.DeleteFile(ctx, filepath.Join(testDirName, testFileName1))
277 _ = store.DeleteFile(ctx, filepath.Join(testDirName, testFileName2))
278 }
279 defer cleanup()
280
281 // Run all tests
282 testWriteFile(tc, testFileName1, testData)

Callers 1

newTestStorageCommandFunction · 0.92

Calls 15

PrintMethod · 0.95
LoggerFunction · 0.92
ParseBackendFunction · 0.92
NewFunction · 0.92
printStepFunction · 0.85
formatBytesFunction · 0.85
cleanupFunction · 0.85
testWriteFileFunction · 0.85
testFileExistsFunction · 0.85
testReadFileFunction · 0.85
testOpenFunction · 0.85
testOpenWithRangeFunction · 0.85

Tested by

no test coverage detected