TestDeltaSyncConcurrentClientCachePopulation tests delta sync behavior when multiple goroutines request the same delta simultaneously. Ensures that only one delta is computed and others wait for the cached result. More instances of duplicated delta computation will be seen for larger documents since
(t *testing.T)
| 1152 | // Ensures that only one delta is computed and others wait for the cached result. |
| 1153 | // More instances of duplicated delta computation will be seen for larger documents since the delta computation takes longer. |
| 1154 | func TestDeltaSyncConcurrentClientCachePopulation(t *testing.T) { |
| 1155 | if !base.IsEnterpriseEdition() { |
| 1156 | t.Skip("Delta sync only supported in EE") |
| 1157 | } |
| 1158 | |
| 1159 | tests := []struct { |
| 1160 | name string |
| 1161 | docSize int |
| 1162 | concurrentClients int |
| 1163 | }{ |
| 1164 | { |
| 1165 | name: "100KBDoc_100Clients", |
| 1166 | docSize: 100 * 1024, |
| 1167 | concurrentClients: 100, |
| 1168 | }, |
| 1169 | { |
| 1170 | name: "100KBDoc_1000Clients", |
| 1171 | docSize: 100 * 1024, |
| 1172 | concurrentClients: 1000, |
| 1173 | }, |
| 1174 | { |
| 1175 | name: "100KBDoc_5000Clients", |
| 1176 | docSize: 100 * 1024, |
| 1177 | concurrentClients: 5000, |
| 1178 | }, |
| 1179 | { |
| 1180 | name: "5MBDoc_10Clients", |
| 1181 | docSize: 5 * 1024 * 1024, |
| 1182 | concurrentClients: 10, |
| 1183 | }, |
| 1184 | { |
| 1185 | name: "5MBDoc_100Clients", |
| 1186 | docSize: 5 * 1024 * 1024, |
| 1187 | concurrentClients: 100, |
| 1188 | }, |
| 1189 | { |
| 1190 | name: "5MBDoc_1000Clients", |
| 1191 | docSize: 5 * 1024 * 1024, |
| 1192 | concurrentClients: 1000, |
| 1193 | }, |
| 1194 | { |
| 1195 | name: "5MBDoc_5000Clients", |
| 1196 | docSize: 5 * 1024 * 1024, |
| 1197 | concurrentClients: 5000, |
| 1198 | }, |
| 1199 | } |
| 1200 | |
| 1201 | for _, test := range tests { |
| 1202 | t.Run(test.name, func(t *testing.T) { |
| 1203 | db, ctx := SetupTestDBWithOptions(t, DatabaseContextOptions{DeltaSyncOptions: DeltaSyncOptions{Enabled: true, RevMaxAgeSeconds: 300}}) |
| 1204 | defer db.Close(ctx) |
| 1205 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 1206 | |
| 1207 | docID := "doc1_" + test.name |
| 1208 | rev1, _, err := collection.Put(ctx, docID, Body{"foo": "bar", "bar": "buzz", "quux": strings.Repeat("a", test.docSize)}) |
| 1209 | require.NoError(t, err) |
| 1210 | rev2, _, err := collection.Put(ctx, docID, Body{"foo": "bar", "quux": strings.Repeat("b", test.docSize), BodyRev: rev1}) |
| 1211 | require.NoError(t, err) |
nothing calls this directly
no test coverage detected