TestBatchRunTasks_Idempotent verifies that BatchRunTasks is idempotent and safe for concurrent calls. This test covers both sequential double-clicks and concurrent requests scenarios.
(t *testing.T)
| 15 | // TestBatchRunTasks_Idempotent verifies that BatchRunTasks is idempotent and safe for concurrent calls. |
| 16 | // This test covers both sequential double-clicks and concurrent requests scenarios. |
| 17 | func TestBatchRunTasks_Idempotent(t *testing.T) { |
| 18 | a := require.New(t) |
| 19 | ctx := context.Background() |
| 20 | ctl := &controller{} |
| 21 | ctx, err := ctl.StartServerWithExternalPg(ctx) |
| 22 | a.NoError(err) |
| 23 | defer ctl.Close(ctx) |
| 24 | |
| 25 | // Provision an instance |
| 26 | instanceRootDir := t.TempDir() |
| 27 | instanceName := "testInstanceIdempotent" |
| 28 | instanceDir, err := ctl.provisionSQLiteInstance(instanceRootDir, instanceName) |
| 29 | a.NoError(err) |
| 30 | |
| 31 | instanceResp, err := ctl.instanceServiceClient.CreateInstance(ctx, connect.NewRequest(&v1pb.CreateInstanceRequest{ |
| 32 | InstanceId: generateRandomString("instance"), |
| 33 | Instance: &v1pb.Instance{ |
| 34 | Title: instanceName, |
| 35 | Engine: v1pb.Engine_SQLITE, |
| 36 | Environment: new("environments/prod"), |
| 37 | Activation: true, |
| 38 | DataSources: []*v1pb.DataSource{{Type: v1pb.DataSourceType_ADMIN, Host: instanceDir, Id: "admin"}}, |
| 39 | }, |
| 40 | })) |
| 41 | a.NoError(err) |
| 42 | instance := instanceResp.Msg |
| 43 | |
| 44 | // Create a database |
| 45 | databaseName := "testIdempotentDb" |
| 46 | err = ctl.createDatabase(ctx, ctl.project, instance, nil /* environment */, databaseName, "") |
| 47 | a.NoError(err) |
| 48 | |
| 49 | databaseResp, err := ctl.databaseServiceClient.GetDatabase(ctx, connect.NewRequest(&v1pb.GetDatabaseRequest{ |
| 50 | Name: fmt.Sprintf("%s/databases/%s", instance.Name, databaseName), |
| 51 | })) |
| 52 | a.NoError(err) |
| 53 | database := databaseResp.Msg |
| 54 | |
| 55 | // Create a sheet with SQL |
| 56 | sheetResp, err := ctl.sheetServiceClient.CreateSheet(ctx, connect.NewRequest(&v1pb.CreateSheetRequest{ |
| 57 | Parent: ctl.project.Name, |
| 58 | Sheet: &v1pb.Sheet{ |
| 59 | Content: []byte("SELECT 1;"), |
| 60 | }, |
| 61 | })) |
| 62 | a.NoError(err) |
| 63 | sheet := sheetResp.Msg |
| 64 | |
| 65 | // Create a plan with change database config |
| 66 | spec := &v1pb.Plan_Spec{ |
| 67 | Id: uuid.NewString(), |
| 68 | Config: &v1pb.Plan_Spec_ChangeDatabaseConfig{ |
| 69 | ChangeDatabaseConfig: &v1pb.Plan_ChangeDatabaseConfig{ |
| 70 | Targets: []string{database.Name}, |
| 71 | Sheet: sheet.Name, |
| 72 | }, |
| 73 | }, |
| 74 | } |
nothing calls this directly
no test coverage detected