| 99 | } |
| 100 | |
| 101 | func TestTable_AddField_Many(t *testing.T) { |
| 102 | if !testutils.IsSingleTesting() { |
| 103 | return |
| 104 | } |
| 105 | |
| 106 | //runtime.GOMAXPROCS(1) |
| 107 | |
| 108 | var table = testOpenStoreTable[*testCachedItem](t, "cache_items", &testCacheItemEncoder[*testCachedItem]{}) |
| 109 | |
| 110 | defer func() { |
| 111 | _ = testingStore.Close() |
| 112 | }() |
| 113 | |
| 114 | { |
| 115 | err := table.AddFields("expiresAt") |
| 116 | if err != nil { |
| 117 | t.Fatal(err) |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | { |
| 122 | err := table.AddFields("staleAt") |
| 123 | if err != nil { |
| 124 | t.Fatal(err) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | { |
| 129 | err := table.AddFields("url") |
| 130 | if err != nil { |
| 131 | t.Fatal(err) |
| 132 | } |
| 133 | } |
| 134 | |
| 135 | var before = time.Now() |
| 136 | const from = 0 |
| 137 | const count = 4_000_000 |
| 138 | |
| 139 | defer func() { |
| 140 | var costSeconds = time.Since(before).Seconds() |
| 141 | t.Log("cost:", costSeconds*1000, "ms", "qps:", int64(float64(count)/costSeconds)) |
| 142 | }() |
| 143 | |
| 144 | for i := from; i < from+count; i++ { |
| 145 | var item = &testCachedItem{ |
| 146 | Hash: "a" + strconv.Itoa(i), |
| 147 | URL: "https://example.com/a" + strconv.Itoa(i), |
| 148 | ExpiresAt: 1710832067 + int64(i), |
| 149 | StaleAt: fasttime.Now().Unix() + int64(i), |
| 150 | CreatedAt: fasttime.Now().Unix(), |
| 151 | } |
| 152 | err := table.Set(item.Hash, item) |
| 153 | if err != nil { |
| 154 | t.Fatal(err) |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |