-
Notifications
You must be signed in to change notification settings - Fork 542
/
snapshotter_test.go
635 lines (613 loc) · 17.7 KB
/
snapshotter_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
// Copyright 2017-2021 Lei Ni (nilei81@gmail.com) and other contributors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package dragonboat
import (
"encoding/binary"
"fmt"
"reflect"
"testing"
"github.com/cockroachdb/errors"
"github.com/lni/goutils/leaktest"
"github.com/lni/dragonboat/v4/config"
"github.com/lni/dragonboat/v4/internal/fileutil"
"github.com/lni/dragonboat/v4/internal/logdb"
"github.com/lni/dragonboat/v4/internal/rsm"
"github.com/lni/dragonboat/v4/internal/vfs"
"github.com/lni/dragonboat/v4/raftio"
pb "github.com/lni/dragonboat/v4/raftpb"
)
const (
tmpSnapshotDirSuffix = "generating"
recvTmpDirSuffix = "receiving"
rdbTestDirectory = "rdb_test_dir_safe_to_delete"
)
func getNewTestDB(dir string, lldir string, fs vfs.IFS) raftio.ILogDB {
d := fs.PathJoin(rdbTestDirectory, dir)
lld := fs.PathJoin(rdbTestDirectory, lldir)
if err := fs.MkdirAll(d, 0777); err != nil {
panic(err)
}
if err := fs.MkdirAll(lld, 0777); err != nil {
panic(err)
}
cfg := config.NodeHostConfig{
Expert: config.GetDefaultExpertConfig(),
}
cfg.Expert.FS = fs
db, err := logdb.NewDefaultLogDB(cfg, nil, []string{d}, []string{lld})
if err != nil {
panic(err.Error())
}
return db
}
func deleteTestRDB(fs vfs.IFS) {
if err := fs.RemoveAll(rdbTestDirectory); err != nil {
panic(err)
}
}
func getTestSnapshotter(ldb raftio.ILogDB, fs vfs.IFS) *snapshotter {
fp := fs.PathJoin(rdbTestDirectory, "snapshot")
if err := fs.MkdirAll(fp, 0777); err != nil {
panic(err)
}
f := func(cid uint64, nid uint64) string {
return fp
}
lr := logdb.NewLogReader(1, 1, ldb)
return newSnapshotter(1, 1, f, ldb, lr, fs)
}
func runSnapshotterTest(t *testing.T,
fn func(t *testing.T, logdb raftio.ILogDB, snapshotter *snapshotter), fs vfs.IFS) {
defer leaktest.AfterTest(t)()
dir := "db-dir"
lldir := "wal-db-dir"
deleteTestRDB(fs)
ldb := getNewTestDB(dir, lldir, fs)
s := getTestSnapshotter(ldb, fs)
defer deleteTestRDB(fs)
defer ldb.Close()
fn(t, ldb, s)
}
func TestFinalizeSnapshotReturnExpectedErrorWhenOutOfDate(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
ss := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 100,
Term: 200,
}
env := s.getEnv(ss.Index)
finalSnapDir := env.GetFinalDir()
if err := fs.MkdirAll(finalSnapDir, 0755); err != nil {
t.Errorf("failed to create final snap dir")
}
if err := env.CreateTempDir(); err != nil {
t.Errorf("create tmp snapshot dir failed %v", err)
}
if err := s.Commit(ss, rsm.SSRequest{}); !errors.Is(err, errSnapshotOutOfDate) {
t.Errorf("unexpected error result %v", err)
}
}
runSnapshotterTest(t, fn, fs)
}
func TestSnapshotCanBeFinalized(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
ss := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 100,
Term: 200,
}
env := s.getEnv(ss.Index)
finalSnapDir := env.GetFinalDir()
tmpDir := env.GetTempDir()
err := env.CreateTempDir()
if err != nil {
t.Errorf("create tmp snapshot dir failed %v", err)
}
_, err = fs.Stat(tmpDir)
if err != nil {
t.Errorf("failed to get stat for tmp dir, %v", err)
}
testfp := fs.PathJoin(tmpDir, "test.data")
f, err := fs.Create(testfp)
if err != nil {
t.Errorf("failed to create test file")
}
if _, err := f.Write(make([]byte, 12)); err != nil {
t.Fatalf("write failed %v", err)
}
f.Close()
if err = s.Commit(ss, rsm.SSRequest{}); err != nil {
t.Errorf("finalize snapshot failed %v", err)
}
snapshot, err := ldb.GetSnapshot(1, 1)
if err != nil {
t.Errorf("failed to list snapshot")
}
if pb.IsEmptySnapshot(snapshot) {
t.Errorf("failed to get snapshot")
}
rs, err := s.GetSnapshotFromLogDB()
if err != nil {
t.Errorf("failed to get snapshot")
}
if rs.Index != 100 {
t.Errorf("returned an unexpected snapshot")
}
if _, err = fs.Stat(tmpDir); !vfs.IsNotExist(err) {
t.Errorf("tmp dir not removed, %v", err)
}
fi, err := fs.Stat(finalSnapDir)
if err != nil {
t.Errorf("failed to get stats, %v", err)
}
if !fi.IsDir() {
t.Errorf("not a dir")
}
if fileutil.HasFlagFile(finalSnapDir, fileutil.SnapshotFlagFilename, fs) {
t.Errorf("flag file not removed")
}
vfp := fs.PathJoin(finalSnapDir, "test.data")
fi, err = fs.Stat(vfp)
if err != nil {
t.Errorf("failed to get stat %v", err)
}
if fi.IsDir() || fi.Size() != 12 {
t.Errorf("not the same test file. ")
}
}
runSnapshotterTest(t, fn, fs)
}
func TestSnapshotCanBeSavedToLogDB(t *testing.T) {
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
s1 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 1,
Term: 2,
}
if err := s.saveSnapshot(s1); err != nil {
t.Errorf("failed to save snapshot record %v", err)
}
snapshot, err := ldb.GetSnapshot(1, 1)
if err != nil {
t.Errorf("failed to list snapshot")
}
if !reflect.DeepEqual(s1, snapshot) {
t.Errorf("snapshot record changed")
}
}
fs := vfs.GetTestFS()
runSnapshotterTest(t, fn, fs)
}
func TestZombieSnapshotDirsCanBeRemoved(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
env1 := s.getEnv(100)
env2 := s.getEnv(200)
fd1 := env1.GetFinalDir()
fd2 := env2.GetFinalDir()
fd1 = fd1 + "-100." + tmpSnapshotDirSuffix
fd2 = fd2 + "-100." + recvTmpDirSuffix
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd2, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if _, err := fs.Stat(fd1); !vfs.IsNotExist(err) {
t.Errorf("fd1 not removed")
}
if _, err := fs.Stat(fd2); !vfs.IsNotExist(err) {
t.Errorf("fd2 not removed")
}
}
runSnapshotterTest(t, fn, fs)
}
func TestSnapshotsNotInLogDBAreRemoved(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
env1 := s.getEnv(100)
env2 := s.getEnv(200)
fd1 := env1.GetFinalDir()
fd2 := env2.GetFinalDir()
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd2, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if _, err := fs.Stat(fd1); !vfs.IsNotExist(err) {
t.Errorf("fd1 %s not removed", fd1)
}
if _, err := fs.Stat(fd2); !vfs.IsNotExist(err) {
t.Errorf("fd2 %s not removed", fd2)
}
}
runSnapshotterTest(t, fn, fs)
}
func TestOnlyMostRecentSnapshotIsKept(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
env1 := s.getEnv(100)
env2 := s.getEnv(200)
env3 := s.getEnv(300)
s1 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 200,
Term: 200,
}
fd1 := env1.GetFinalDir()
fd2 := env2.GetFinalDir()
fd3 := env3.GetFinalDir()
if err := s.saveSnapshot(s1); err != nil {
t.Errorf("failed to save snapshot to logdb")
}
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd2, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd3, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if _, err := fs.Stat(fd1); !vfs.IsNotExist(err) {
t.Errorf("fd1 %s not removed", fd1)
}
if _, err := fs.Stat(fd2); vfs.IsNotExist(err) {
t.Errorf("fd2 %s removed by mistake", fd2)
}
if _, err := fs.Stat(fd3); !vfs.IsNotExist(err) {
t.Errorf("fd3 %s not removed", fd3)
}
}
runSnapshotterTest(t, fn, fs)
}
func TestFirstSnapshotBecomeOrphanedIsHandled(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
s1 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 100,
Term: 200,
}
env := s.getEnv(100)
fd1 := env.GetFinalDir()
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if _, err := fs.Stat(fd1); !vfs.IsNotExist(err) {
t.Errorf("fd1 not removed")
}
}
runSnapshotterTest(t, fn, fs)
}
func TestOrphanedSnapshotRecordIsRemoved(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
s1 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 100,
Term: 200,
}
s2 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 200,
Term: 200,
}
env1 := s.getEnv(s1.Index)
env2 := s.getEnv(s2.Index)
fd1 := env1.GetFinalDir()
fd2 := env2.GetFinalDir()
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd2, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := fileutil.CreateFlagFile(fd2, fileutil.SnapshotFlagFilename, &s2, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := s.saveSnapshot(s1); err != nil {
t.Errorf("failed to save snapshot to logdb")
}
if err := s.saveSnapshot(s2); err != nil {
t.Errorf("failed to save snapshot to logdb")
}
// two orphane snapshots, kept the most recent one, and remove the older
// one including its logdb record.
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if _, err := fs.Stat(fd1); vfs.IsExist(err) {
t.Errorf("failed to remove fd1")
}
if _, err := fs.Stat(fd2); vfs.IsNotExist(err) {
t.Errorf("unexpectedly removed fd2")
}
if fileutil.HasFlagFile(fd2, fileutil.SnapshotFlagFilename, fs) {
t.Errorf("flag for fd2 not removed")
}
snapshot, err := s.logdb.GetSnapshot(1, 1)
if err != nil {
t.Fatalf("failed to list snapshot %v", err)
}
if snapshot.Index != 200 {
t.Fatalf("unexpected record %v", snapshot)
}
}
runSnapshotterTest(t, fn, fs)
}
func TestOrphanedSnapshotsCanBeProcessed(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
s1 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 100,
Term: 200,
}
s2 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 200,
Term: 200,
}
s3 := pb.Snapshot{
FileSize: 1234,
Filepath: "f2",
Index: 300,
Term: 200,
}
env1 := s.getEnv(s1.Index)
env2 := s.getEnv(s2.Index)
env3 := s.getEnv(s3.Index)
fd1 := env1.GetFinalDir()
fd2 := env2.GetFinalDir()
fd3 := env3.GetFinalDir()
fd4 := fmt.Sprintf("%s%s", fd3, "xx")
if err := fs.MkdirAll(fd1, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd2, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fs.MkdirAll(fd4, 0755); err != nil {
t.Errorf("failed to create dir %v", err)
}
if err := fileutil.CreateFlagFile(fd1, fileutil.SnapshotFlagFilename, &s1, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := fileutil.CreateFlagFile(fd2, fileutil.SnapshotFlagFilename, &s2, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := fileutil.CreateFlagFile(fd4, fileutil.SnapshotFlagFilename, &s3, fs); err != nil {
t.Errorf("failed to create flag file %s", err)
}
if err := s.saveSnapshot(s1); err != nil {
t.Errorf("failed to save snapshot to logdb")
}
// fd1 has record in logdb. flag file expected to be removed while the fd1
// foler is expected to be kept
// fd2 doesn't has its record in logdb, while the most recent snapshot record
// in logdb is not for fd2, fd2 will be entirely removed
if err := s.processOrphans(); err != nil {
t.Errorf("failed to process orphaned snapshtos %s", err)
}
if fileutil.HasFlagFile(fd1, fileutil.SnapshotFlagFilename, fs) {
t.Errorf("flag for fd1 not removed")
}
if fileutil.HasFlagFile(fd2, fileutil.SnapshotFlagFilename, fs) {
t.Errorf("flag for fd2 not removed")
}
if !fileutil.HasFlagFile(fd4, fileutil.SnapshotFlagFilename, fs) {
t.Errorf("flag for fd4 is missing")
}
if _, err := fs.Stat(fd1); vfs.IsNotExist(err) {
t.Errorf("fd1 removed by mistake")
}
if _, err := fs.Stat(fd2); !vfs.IsNotExist(err) {
t.Errorf("fd2 not removed")
}
}
runSnapshotterTest(t, fn, fs)
}
func TestSnapshotterCompact(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, snapshotter *snapshotter) {
for i := uint64(1); i <= uint64(3); i++ {
fn := fmt.Sprintf("f%d.data", i)
s := pb.Snapshot{
FileSize: 1234,
Filepath: fn,
Index: i,
Term: 2,
}
env := snapshotter.getEnv(s.Index)
if err := env.CreateTempDir(); err != nil {
t.Errorf("failed to create snapshot dir")
}
if err := snapshotter.Commit(s, rsm.SSRequest{}); err != nil {
t.Errorf("failed to save snapshot record")
}
fp := snapshotter.getFilePath(s.Index)
f, err := fs.Create(fp)
if err != nil {
t.Errorf("failed to create the file, %v", err)
}
f.Close()
}
if err := snapshotter.Compact(2); err != nil {
t.Errorf("failed to remove unused snapshots, %v", err)
}
check := func(index uint64, exist bool) {
env := snapshotter.getEnv(index)
snapDir := env.GetFinalDir()
_, err := fs.Stat(snapDir)
if exist && vfs.IsNotExist(err) {
t.Errorf("snapshot dir didn't get removed")
}
if !exist && !vfs.IsNotExist(err) {
t.Errorf("failed to be removed")
}
}
check(1, true)
check(2, false)
check(3, true)
}
runSnapshotterTest(t, fn, fs)
}
func TestShrinkSnapshots(t *testing.T) {
fs := vfs.GetTestFS()
fn := func(t *testing.T, ldb raftio.ILogDB, snapshotter *snapshotter) {
for i := uint64(1); i <= 3; i++ {
index := i * 10
env := snapshotter.getEnv(index)
fp := env.GetFilepath()
s := pb.Snapshot{
Index: index,
Term: 2,
FileSize: 1234,
Filepath: fp,
}
if err := env.CreateTempDir(); err != nil {
t.Errorf("failed to create snapshot dir")
}
if err := snapshotter.Commit(s, rsm.SSRequest{}); err != nil {
t.Errorf("failed to save snapshot record")
}
fp = snapshotter.getFilePath(s.Index)
writer, err := rsm.NewSnapshotWriter(fp, pb.NoCompression, fs)
if err != nil {
t.Fatalf("failed to create the snapshot %v", err)
}
sz := make([]byte, 8)
binary.LittleEndian.PutUint64(sz, 0)
if _, err := writer.Write(sz); err != nil {
t.Fatalf("failed to write %v", err)
}
for j := 0; j < 10; j++ {
data := make([]byte, 1024*1024)
if _, err := writer.Write(data); err != nil {
t.Fatalf("failed to write %v", err)
}
}
if err := writer.Close(); err != nil {
t.Fatalf("close failed %v", err)
}
}
if err := snapshotter.Shrink(20); err != nil {
t.Fatalf("shrink snapshots failed %v", err)
}
env1 := snapshotter.getEnv(10)
env2 := snapshotter.getEnv(20)
env3 := snapshotter.getEnv(30)
cf := func(p string, esz uint64) {
fi, err := fs.Stat(p)
if err != nil {
t.Fatalf("failed to get file st %v", err)
}
if uint64(fi.Size()) != esz {
// 1024 header, 8 size client session size, 8 bytes client session
// count, 4 bytes crc, 16 bytes tails 1052 bytes in total
t.Fatalf("unexpected size %d, want %d", fi.Size(), esz)
}
}
cf(env1.GetFilepath(), 10486832)
cf(env2.GetFilepath(), 1060)
cf(env3.GetFilepath(), 10486832)
}
runSnapshotterTest(t, fn, fs)
}
func TestSnapshotDirNameMatchWorks(t *testing.T) {
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
tests := []struct {
dirName string
valid bool
}{
{"snapshot-AB", true},
{"snapshot", false},
{"xxxsnapshot-AB", false},
{"snapshot-ABd", false},
{"snapshot-", false},
}
for idx, tt := range tests {
v := s.dirMatch(tt.dirName)
if v != tt.valid {
t.Errorf("dir name %s (%d) failed to match", tt.dirName, idx)
}
}
}
fs := vfs.GetTestFS()
runSnapshotterTest(t, fn, fs)
}
func TestZombieSnapshotDirNameMatchWorks(t *testing.T) {
fn := func(t *testing.T, ldb raftio.ILogDB, s *snapshotter) {
tests := []struct {
dirName string
valid bool
}{
{"snapshot-AB", false},
{"snapshot", false},
{"xxxsnapshot-AB", false},
{"snapshot-", false},
{"snapshot-AB-01.receiving", true},
{"snapshot-AB-1G.receiving", false},
{"snapshot-AB.receiving", false},
{"snapshot-XX.receiving", false},
{"snapshot-AB.receivingd", false},
{"dsnapshot-AB.receiving", false},
{"snapshot-AB.generating", false},
{"snapshot-AB-01.generating", true},
{"snapshot-AB-0G.generating", false},
{"snapshot-XX.generating", false},
{"snapshot-AB.generatingd", false},
{"dsnapshot-AB.generating", false},
}
for idx, tt := range tests {
v := s.isZombie(tt.dirName)
if v != tt.valid {
t.Errorf("dir name %s (%d) failed to match", tt.dirName, idx)
}
}
}
fs := vfs.GetTestFS()
runSnapshotterTest(t, fn, fs)
}