|
| 1 | +package integ |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strconv" |
| 6 | + "testing" |
| 7 | + "time" |
| 8 | + |
| 9 | + s3_upsert_data_objects "github.com/indeedeng/iwf/integ/workflow/s3-upsert-data-objects" |
| 10 | + |
| 11 | + "github.com/indeedeng/iwf/service/common/ptr" |
| 12 | + |
| 13 | + "github.com/indeedeng/iwf/gen/iwfidl" |
| 14 | + "github.com/indeedeng/iwf/service" |
| 15 | + "github.com/stretchr/testify/assert" |
| 16 | +) |
| 17 | + |
| 18 | +func TestS3WorkflowUpsertDataObjectsTemporal(t *testing.T) { |
| 19 | + if !*temporalIntegTest { |
| 20 | + t.Skip() |
| 21 | + } |
| 22 | + |
| 23 | + for i := 0; i < *repeatIntegTest; i++ { |
| 24 | + doTestWorkflowWithS3UpsertDataObjects(t, service.BackendTypeTemporal) |
| 25 | + smallWaitForFastTest() |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +func TestS3WorkflowUpsertDataObjectsCadence(t *testing.T) { |
| 30 | + if !*cadenceIntegTest { |
| 31 | + t.Skip() |
| 32 | + } |
| 33 | + for i := 0; i < *repeatIntegTest; i++ { |
| 34 | + doTestWorkflowWithS3UpsertDataObjects(t, service.BackendTypeCadence) |
| 35 | + smallWaitForFastTest() |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +func doTestWorkflowWithS3UpsertDataObjects(t *testing.T, backendType service.BackendType) { |
| 40 | + // start test workflow server |
| 41 | + wfHandler := s3_upsert_data_objects.NewHandler() |
| 42 | + closeFunc1 := startWorkflowWorker(wfHandler, t) |
| 43 | + defer closeFunc1() |
| 44 | + |
| 45 | + _, closeFunc2 := startIwfServiceByConfig(IwfServiceTestConfig{ |
| 46 | + BackendType: backendType, |
| 47 | + S3TestThreshold: 10, // Set low threshold so our test data gets stored in S3 |
| 48 | + }) |
| 49 | + defer closeFunc2() |
| 50 | + |
| 51 | + // start a workflow |
| 52 | + apiClient := iwfidl.NewAPIClient(&iwfidl.Configuration{ |
| 53 | + Servers: []iwfidl.ServerConfiguration{ |
| 54 | + { |
| 55 | + URL: "http://localhost:" + testIwfServerPort, |
| 56 | + }, |
| 57 | + }, |
| 58 | + }) |
| 59 | + wfId := s3_upsert_data_objects.WorkflowType + strconv.Itoa(int(time.Now().UnixNano())) |
| 60 | + |
| 61 | + // Create small input |
| 62 | + wfInput := &iwfidl.EncodedObject{ |
| 63 | + Encoding: iwfidl.PtrString("json"), |
| 64 | + Data: iwfidl.PtrString("\"test\""), |
| 65 | + } |
| 66 | + |
| 67 | + req := apiClient.DefaultApi.ApiV1WorkflowStartPost(context.Background()) |
| 68 | + startReq := iwfidl.WorkflowStartRequest{ |
| 69 | + WorkflowId: wfId, |
| 70 | + IwfWorkflowType: s3_upsert_data_objects.WorkflowType, |
| 71 | + WorkflowTimeoutSeconds: 100, |
| 72 | + IwfWorkerUrl: "http://localhost:" + testWorkflowServerPort, |
| 73 | + StartStateId: ptr.Any(s3_upsert_data_objects.State1), |
| 74 | + StateInput: wfInput, |
| 75 | + } |
| 76 | + _, httpResp, err := req.WorkflowStartRequest(startReq).Execute() |
| 77 | + failTestAtHttpError(err, httpResp, t) |
| 78 | + |
| 79 | + req2 := apiClient.DefaultApi.ApiV1WorkflowGetWithWaitPost(context.Background()) |
| 80 | + _, httpResp2, err2 := req2.WorkflowGetRequest(iwfidl.WorkflowGetRequest{ |
| 81 | + WorkflowId: wfId, |
| 82 | + }).Execute() |
| 83 | + failTestAtHttpError(err2, httpResp2, t) |
| 84 | + |
| 85 | + assertions := assert.New(t) |
| 86 | + |
| 87 | + _, history := wfHandler.GetTestResult() |
| 88 | + |
| 89 | + // Verify all states were executed |
| 90 | + assertions.Equal(history["S1_start"], int64(1), "S1_start should be called once") |
| 91 | + assertions.Equal(history["S1_decide"], int64(1), "S1_decide should be called once") |
| 92 | + assertions.Equal(history["S2_start"], int64(1), "S2_start should be called once") |
| 93 | + assertions.Equal(history["S2_decide"], int64(1), "S2_decide should be called once") |
| 94 | + |
| 95 | + // Verify State2 received the large data objects that were upserted by State1 |
| 96 | + assertions.Equal(history["S2_received_large_obj1"], true, "S2 should receive large_obj1 from State1's upsert") |
| 97 | + assertions.Equal(history["S2_received_large_obj2"], true, "S2 should receive large_obj2 from State1's upsert") |
| 98 | + assertions.Equal(history["S2_received_small_obj3"], true, "S2 should receive small_obj3 from State1's upsert") |
| 99 | + |
| 100 | + // Verify the data content matches what State1 upserted |
| 101 | + assertions.Equal(history["S2_large_obj1_data"], s3_upsert_data_objects.LargeDataContent1, "S2 large_obj1 data should match") |
| 102 | + assertions.Equal(history["S2_large_obj2_data"], s3_upsert_data_objects.LargeDataContent2, "S2 large_obj2 data should match") |
| 103 | + assertions.Equal(history["S2_small_obj3_data"], s3_upsert_data_objects.SmallDataContent3, "S2 small_obj3 data should match") |
| 104 | + |
| 105 | + // Verify external storage usage: 2 large objects should be in S3, small one should stay in memory |
| 106 | + objectCount, err := globalBlobStore.CountWorkflowObjectsForTesting(context.Background(), wfId) |
| 107 | + assertions.Nil(err) |
| 108 | + assertions.Equal(int64(2), objectCount, "Should have 2 objects in S3 (large_obj1 and large_obj2)") |
| 109 | +} |
0 commit comments