|
1 | 1 | package concurrent_cache |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "fmt" |
5 | 6 | "math/rand" |
6 | 7 | "reflect" |
@@ -266,7 +267,7 @@ func TestLock(t *testing.T) { |
266 | 267 | for i := 0; i < n; i++ { |
267 | 268 | go func() { |
268 | 269 | defer wg.Done() |
269 | | - results, unlocker, err := Lock(makeQueries()...) |
| 270 | + results, unlocker, err := Lock(context.Background(), makeQueries()...) |
270 | 271 | defer unlocker() |
271 | 272 | assert.NoError(t, err) |
272 | 273 | assert.NotNil(t, results[2].VolumePublication.Upsert) |
@@ -479,7 +480,7 @@ func TestLockNeverDeadlocks(t *testing.T) { |
479 | 480 | for i := 0; i < tc.numQueries; i++ { |
480 | 481 | queries[i] = generateRandomQuery(queryGenerators[rand.Intn(len(queryGenerators))], tc.maxSubqueriesPerQuery) |
481 | 482 | } |
482 | | - results, unlock, err := Lock(queries...) |
| 483 | + results, unlock, err := Lock(context.Background(), queries...) |
483 | 484 | defer unlock() |
484 | 485 | time.Sleep(time.Duration(10+rand.Intn(40)) * time.Millisecond) // Simulate some processing time |
485 | 486 | for _, operation := range []string{"Upsert", "Delete"} { |
@@ -616,7 +617,7 @@ func TestLockWithDependencyChains(t *testing.T) { |
616 | 617 | var err error |
617 | 618 |
|
618 | 619 | go func() { |
619 | | - results, unlock, err = Lock(tc.querySets...) |
| 620 | + results, unlock, err = Lock(context.Background(), tc.querySets...) |
620 | 621 | time.Sleep(10 * time.Millisecond) // Simulate some processing time |
621 | 622 | for _, operation := range []string{"Upsert", "Delete"} { |
622 | 623 | doOperation(t, operation, results) |
@@ -776,3 +777,11 @@ func cleanupTestData() { |
776 | 777 | volumePublications.data = make(map[string]SmartCopier) |
777 | 778 | volumePublications.unlock() |
778 | 779 | } |
| 780 | + |
| 781 | +func TestLockCancel(t *testing.T) { |
| 782 | + ctx, cancel := context.WithTimeout(context.Background(), -1*time.Second) |
| 783 | + defer cancel() |
| 784 | + _, unlocker, err := Lock(ctx, Query(UpsertNode("node1"))) |
| 785 | + defer unlocker() |
| 786 | + assert.ErrorContains(t, err, "context deadline exceeded") |
| 787 | +} |
0 commit comments