TestCloseSyncWhileFillEmpty test the sync can be cancel while the fill empty is running.
(t *testing.T)
| 1079 | |
| 1080 | // TestCloseSyncWhileFillEmpty test the sync can be cancel while the fill empty is running. |
| 1081 | func TestCloseSyncWhileFillEmpty(t *testing.T) { |
| 1082 | var ( |
| 1083 | kvSize = defaultChunkSize |
| 1084 | kvEntries = uint64(512) |
| 1085 | lastKvIndex = uint64(0) |
| 1086 | db = rawdb.NewMemoryDatabase() |
| 1087 | mux = new(event.Feed) |
| 1088 | shards = []uint64{0} |
| 1089 | shardMap = make(map[common.Address][]uint64) |
| 1090 | m = metrics.NewMetrics("sync_test") |
| 1091 | chainID = new(big.Int).SetUint64(3333) |
| 1092 | ) |
| 1093 | |
| 1094 | metafile, err := CreateMetaFile(metafileName, int64(kvEntries)) |
| 1095 | if err != nil { |
| 1096 | t.Error("Create metafileName fail", err.Error()) |
| 1097 | } |
| 1098 | defer metafile.Close() |
| 1099 | |
| 1100 | shardMap[contract] = shards |
| 1101 | shardManager, files := createEthStorage(contract, shards, defaultChunkSize, kvSize, kvEntries, common.Address{}, defaultEncodeType) |
| 1102 | if shardManager == nil { |
| 1103 | t.Fatalf("createEthStorage failed") |
| 1104 | } |
| 1105 | defer func(files []string) { |
| 1106 | for _, file := range files { |
| 1107 | os.Remove(file) |
| 1108 | } |
| 1109 | }(files) |
| 1110 | |
| 1111 | makeKVStorage(contract, shards, defaultChunkSize, kvSize, kvEntries, lastKvIndex, common.Address{}, defaultEncodeType, metafile) |
| 1112 | |
| 1113 | l1 := NewMockL1Source(lastKvIndex, metafileName) |
| 1114 | sm := ethstorage.NewStorageManager(shardManager, l1, lg) |
| 1115 | sm.Reset(0) |
| 1116 | _, syncCl := createLocalHostAndSyncClient(t, chainID, db, sm, m, mux) |
| 1117 | syncCl.Start() |
| 1118 | time.Sleep(10 * time.Millisecond) |
| 1119 | syncCl.Close() |
| 1120 | |
| 1121 | t.Log("Fill empty status", "filled", syncCl.tasks[0].state.EmptyFilled, "toFill", syncCl.tasks[0].state.EmptyToFill) |
| 1122 | if syncCl.syncDone { |
| 1123 | t.Fatalf("fill empty should be cancel") |
| 1124 | } |
| 1125 | } |
| 1126 | |
| 1127 | // TestAddPeerAfterSyncDone test add peer after sync done, the peer should add successfully (the connection is kept), |
| 1128 | // as the remote peer may need to sync data from this local peer, we also need to use the sync client to control |
nothing calls this directly
no test coverage detected