Multiple clients are attempting to push the same new, non-winning revision concurrently; non-winning is an update to a non-winning branch that leaves the branch still non-winning (i.e. shorter) than the active branch
(t *testing.T)
| 3421 | // Multiple clients are attempting to push the same new, non-winning revision concurrently; non-winning is an |
| 3422 | // update to a non-winning branch that leaves the branch still non-winning (i.e. shorter) than the active branch |
| 3423 | func TestConcurrentPushSameNewNonWinningRevision(t *testing.T) { |
| 3424 | base.SetUpTestLogging(t, base.LevelDebug, base.KeyCRUD) |
| 3425 | var db *Database |
| 3426 | var enableCallback bool |
| 3427 | ctx := base.TestCtx(t) |
| 3428 | |
| 3429 | bucket := base.GetTestBucket(t) |
| 3430 | defer bucket.Close(ctx) |
| 3431 | |
| 3432 | leakyBucket := base.NewLeakyBucket(bucket, base.LeakyBucketConfig{ |
| 3433 | UpdateCallback: func(key string) { |
| 3434 | if enableCallback { |
| 3435 | enableCallback = false |
| 3436 | body := Body{"name": "Emily", "age": 20} |
| 3437 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 3438 | _, _, err := collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"3-b", "2-b", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3439 | assert.NoError(t, err, "Adding revision 3-b") |
| 3440 | } |
| 3441 | }, |
| 3442 | }) |
| 3443 | |
| 3444 | db, ctx = SetupTestDBForBucketWithOptions(t, leakyBucket, DatabaseContextOptions{AllowConflicts: base.Ptr(true)}) |
| 3445 | defer db.Close(ctx) |
| 3446 | collection, ctx := GetSingleDatabaseCollectionWithUser(ctx, t, db) |
| 3447 | |
| 3448 | body := Body{"name": "Olivia", "age": 80} |
| 3449 | _, _, err := collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3450 | assert.NoError(t, err, "Adding revision 1-a") |
| 3451 | |
| 3452 | body = Body{"name": "Harry", "age": 40} |
| 3453 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3454 | assert.NoError(t, err, "Adding revision 2-a") |
| 3455 | |
| 3456 | body = Body{"name": "Amelia", "age": 20} |
| 3457 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"3-a", "2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3458 | assert.NoError(t, err, "Adding revision 3-a") |
| 3459 | |
| 3460 | body = Body{"name": "Charlie", "age": 10} |
| 3461 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"4-a", "3-a", "2-a", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3462 | assert.NoError(t, err, "Adding revision 4-a") |
| 3463 | |
| 3464 | body = Body{"name": "Noah", "age": 40} |
| 3465 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"2-b", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3466 | assert.NoError(t, err, "Adding revision 2-b") |
| 3467 | |
| 3468 | enableCallback = true |
| 3469 | |
| 3470 | body = Body{"name": "Emily", "age": 20} |
| 3471 | _, _, err = collection.PutExistingRevWithBody(ctx, "doc1", body, []string{"3-b", "2-b", "1-a"}, false, ExistingVersionWithUpdateToHLV) |
| 3472 | assert.NoError(t, err, "Adding revision 3-b") |
| 3473 | |
| 3474 | doc, err := collection.GetDocument(ctx, "doc1", DocUnmarshalAll) |
| 3475 | assert.NoError(t, err, "Retrieve doc after adding 3-b") |
| 3476 | assert.Equal(t, "4-a", doc.GetRevTreeID()) |
| 3477 | } |
| 3478 | |
| 3479 | // Multiple clients are attempting to push the same tombstone of the winning revision for a branched document |
| 3480 | // First writer should be successful, subsequent writers should fail on CAS, then identify rev already exists |
nothing calls this directly
no test coverage detected