dhiaayachi / temporal

Temporal service
https://docs.temporal.io
MIT License
0 stars 0 forks source link

Unit test error in v1.24.2 #102

Open dhiaayachi opened 2 weeks ago

dhiaayachi commented 2 weeks ago

Expected Behavior

Unit tests should pass

Actual Behavior

Unit tests do not pass

Steps to Reproduce the Problem

  1. Checkout tag v1.24.2 or release/v1.24.x
  2. Run unit tests, either via make unit-test-coverage or go test ./service/history/workflow/...
  3. Observe failure
=== Failed
=== FAIL: service/history/workflow TestMutableStateSuite/TestTotalEntitiesCount (0.00s)
2024-07-22T22:38:14.867Z    info    Task key range updated  {"number": 1048576, "next-number": 2097152, "logging-call-at": "task_key_generator.go:177"}
    controller.go:231: missing call(s) to *cluster.MockMetadata.ClusterNameForFailoverVersion(is equal to false (bool), is equal to 1234 (int64)) /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1087
    controller.go:231: missing call(s) to *cluster.MockMetadata.GetCurrentClusterName() /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1091
    controller.go:231: aborting test due to missing call(s)

=== FAIL: service/history/workflow TestMutableStateSuite (0.05s)

DONE 4541 tests, 7 skipped, 2 failures in 665.189s
make: *** [Makefile:405: unit-test-coverage] Error 1

Specifications

dhiaayachi commented 23 hours ago

Expected Behavior

Unit tests should pass.

Actual Behavior

Unit tests do not pass.

Steps to Reproduce the Problem

  1. Checkout tag v1.24.2 or release/v1.24.x
  2. Run unit tests, either via make unit-test-coverage or go test ./service/history/workflow/...
  3. Observe failure
=== Failed
=== FAIL: service/history/workflow TestMutableStateSuite/TestTotalEntitiesCount (0.00s)
2024-07-22T22:38:14.867Z    info    Task key range updated  {"number": 1048576, "next-number": 2097152, "logging-call-at": "task_key_generator.go:177"}
    controller.go:231: missing call(s) to *cluster.MockMetadata.ClusterNameForFailoverVersion(is equal to false (bool), is equal to 1234 (int64)) /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1087
    controller.go:231: missing call(s) to *cluster.MockMetadata.GetCurrentClusterName() /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1091
    controller.go:231: aborting test due to missing call(s)

=== FAIL: service/history/workflow TestMutableStateSuite (0.05s)

DONE 4541 tests, 7 skipped, 2 failures in 665.189s
make: *** [Makefile:405: unit-test-coverage] Error 1

Specifications

Root Cause

The issue is related to the missing calls in TestMutableStateSuite, specifically in the TestTotalEntitiesCount test. The test expects cluster.MockMetadata to be called in two specific ways:

These calls are not being made, causing the test to fail.

Possible Solution

The solution lies in ensuring that the cluster.MockMetadata instance in the test is set up correctly and that the relevant methods are called during the test execution.

This could involve:

  1. Inspecting the TestTotalEntitiesCount test: Check the implementation and identify why the calls are missing. This might involve verifying the logic within the test and ensuring the correct mock methods are being called.
  2. Adding the missing calls: If the test's logic is correct, you might need to add explicit calls to the mock object within the test. This would ensure that the test environment correctly mocks the necessary interactions.
  3. Updating the cluster.MockMetadata instance: Ensure that the cluster.MockMetadata instance is properly initialized and configured to support the expected behavior. This might require reviewing the setup of the mock object and verifying its initialization and configuration.

Recommendation

Please review the TestTotalEntitiesCount test in service/history/workflow/mutable_state_impl_test.go, focusing on the calls to cluster.MockMetadata. Ensure that the mock object is correctly set up and that the relevant methods are being called. If necessary, add the missing calls or adjust the cluster.MockMetadata instance to address the issue.

By verifying the calls to cluster.MockMetadata, you can ensure the unit test correctly simulates the expected behavior and validate the logic within the test. This should resolve the failure and ensure that the unit tests pass.

Please note: This response is based on the provided context and assumes the issue is isolated to the TestTotalEntitiesCount test and the cluster.MockMetadata setup. Additional investigation might be needed depending on the specific implementation of the test.

dhiaayachi commented 21 hours ago

Expected Behavior

Unit tests should pass

Actual Behavior

Unit tests do not pass

Steps to Reproduce the Problem

  1. Checkout tag v1.24.2 or release/v1.24.x
  2. Run unit tests, either via make unit-test-coverage or go test ./service/history/workflow/...
  3. Observe failure
=== Failed
=== FAIL: service/history/workflow TestMutableStateSuite/TestTotalEntitiesCount (0.00s)
2024-07-22T22:38:14.867Z    info    Task key range updated  {"number": 1048576, "next-number": 2097152, "logging-call-at": "task_key_generator.go:177"}
    controller.go:231: missing call(s) to *cluster.MockMetadata.ClusterNameForFailoverVersion(is equal to false (bool), is equal to 1234 (int64)) /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1087
    controller.go:231: missing call(s) to *cluster.MockMetadata.GetCurrentClusterName() /home/runner/work/temporal/temporal/service/history/workflow/mutable_state_impl_test.go:1091
    controller.go:231: aborting test due to missing call(s)

=== FAIL: service/history/workflow TestMutableStateSuite (0.05s)

DONE 4541 tests, 7 skipped, 2 failures in 665.189s
make: *** [Makefile:405: unit-test-coverage] Error 1

Specifications

Thanks for reporting this issue.

It seems like your tests are failing because controller.go doesn't have the expected calls for *cluster.MockMetadata.ClusterNameForFailoverVersion and *cluster.MockMetadata.GetCurrentClusterName.

Could you please share the code for the TestMutableStateSuite test suite? I need the code from mutable_state_impl_test.go to investigate the issue further.

dhiaayachi commented 21 hours ago

Thanks for reporting this issue.

It seems like there's an issue with how the MockMetadata is being used in the test. Specifically, it looks like the test is expecting calls to ClusterNameForFailoverVersion and GetCurrentClusterName that are not being made.

To solve this, you'll need to ensure that the mock object is correctly set up to meet the expectations of the test.

Here's how you can approach troubleshooting:

  1. Verify Mock Expectations: Make sure the MockMetadata object has the appropriate expectations set for the functions ClusterNameForFailoverVersion and GetCurrentClusterName. You'll need to use the mocking framework's APIs to define the expected calls.

  2. Inspect the Test Code: Examine the test code closely to understand how the MockMetadata is used and how the Workflow code interacts with it. This will help you identify any discrepancies between the mock's setup and the actual usage in the test.

  3. Review the Workflow Code: Check the relevant portion of the Workflow code, specifically where the MockMetadata is being used, and verify that it's being called as expected by the test.

  4. Console Logging: Add console logging statements inside the test code and Workflow code to print the values being passed to the MockMetadata object. This can help you understand the actual calls and identify any inconsistencies.

  5. Minimal Reproducible Example: If possible, create a smaller, isolated test case that demonstrates the issue to make it easier to troubleshoot. This will help you focus your efforts on the core problem.

  6. Community Forum: If you are unable to resolve the issue, consider posting on Temporal's community forum ( https://community.temporal.io/) for help from the Temporal community.

Please provide the following information so I can assist you further:

Let me know if you have any further questions!

dhiaayachi commented 21 hours ago

Thanks for reporting this issue. The error message indicates that the unit tests are failing because the mock metadata is not being called as expected.

Here are a few things to check:

If you've already checked these items and still encounter the issue, please provide more context.

Let me know if you have any other questions. I'm happy to help you resolve this issue.

dhiaayachi commented 20 hours ago

Thanks for reporting this. The unit tests are failing due to the missing calls to ClusterNameForFailoverVersion and GetCurrentClusterName methods of the mock metadata in mutable_state_impl_test.go. This indicates that the logic is expecting these methods to be called, but the mock is not fulfilling these expectations.

To resolve this, you can add the missing calls to the mock metadata in the test. For example:

// This is the test method, this is just an example, make sure you adjust it to fit the logic of the original method
func TestTotalEntitiesCount(t *testing.T) {
    env := NewTestWorkflowEnvironment()
    // Make sure the test environment is stopped after the test is completed
    defer env.Close()
    ms := NewMutableState(env.GetMockBackend(), env.GetClient(), env.GetLogger(), env.GetMetricsScope(), 10, time.Minute, time.Minute, time.Second, 1, 1)
    // ... Your setup for the test goes here
    env.GetMockBackend().Metadata.On("ClusterNameForFailoverVersion", mock.Anything).Return("your-cluster-name", nil)
    env.GetMockBackend().Metadata.On("GetCurrentClusterName").Return("your-cluster-name")
    // ... The rest of your test goes here

}

You can also check the Temporal documentation on testing for more information on mocking and testing.

dhiaayachi commented 19 hours ago

Thanks for reporting the issue. I see the unit tests are failing on v1.24.2. The failures are happening due to missing mock calls in the TestMutableStateSuite tests:

To fix the issue, you can add these mock calls to the tests to ensure that the mock functions are called as expected.

Please refer to the documentation for more information: Temporal CLI workflow command reference.

dhiaayachi commented 5 hours ago

Thanks for reporting this issue. The error seems to be caused by missing mock calls for cluster.MockMetadata.ClusterNameForFailoverVersion() and cluster.MockMetadata.GetCurrentClusterName(). Could you confirm that the mock implementation of cluster.MockMetadata is correct and if these calls are expected?