run and runInParallel does not hace the same behaviour (matlab.un​ittest.Tes​tRunner)

2 views (last 30 days)
In a custom testCase class, I test the equality:
testCase.verifyThat(struct_gen, matlab.unittest.constraints.IsEqualTo(struct_baseline));
For a series of parametrized tests, the test running is ok with:
runner = TestRunner.withTextOutput;
result_load = runner.run(suite)
But the (same) test failed with parallel running :
result_load = runner.runInParallel(suite)
It seems to fail for custom structure (but why it's ok with run and not with runInParallel ... ??)

Answers (1)

Yash
Yash on 6 Oct 2023
Hi Luc,
I understand that you are facing issues while using the "runInParallel" function. Without the full code, it is difficult to determine the exact reason for the problem. However, I can provide you with some possible reasons that may be causing this issue:
  1. Race conditions: Parallel execution introduces the possibility of race conditions, where multiple threads or processes access and modify shared data simultaneously. If your custom structure is not designed to handle concurrent access correctly, it may lead to unexpected behavior and test failures.
  2. Shared resources: Parallel execution may involve sharing resources such as files, network connections, or external services. If your custom structure relies on any of these shared resources, it could cause conflicts or inconsistencies when accessed concurrently by multiple test cases.
  3. Dependency issues: Some custom structures might have dependencies on external libraries or functions that are not thread-safe. When running tests in parallel, these dependencies may not be handled correctly, leading to failures.
  4. Data Sharing: When running tests in parallel, each test case is executed in a separate MATLAB worker process. These worker processes operate independently and do not share memory with each other. Therefore, any custom structures or objects used in the test cases need to be explicitly shared among the workers.
To troubleshoot the issue, you can try the following steps:
  1. Check for thread safety: Review your custom structure implementation and ensure that it is designed to handle concurrent access correctly. Look for any shared data or mutable state that might cause issues in a parallel execution environment.
  2. Isolate the failing test: If possible, isolate the failing test case and run it separately using runInParallel. This will help identify if the issue is specific to the test case or if it occurs with other tests as well.
  3. Review dependencies: Check if your custom structure relies on any external libraries or functions that might not be thread-safe. Look for any known issues or limitations related to parallel execution with these dependencies.
  4. Debug with logging: Add logging statements or debug output to your test case and custom structure to gather more information about the failure. This can help identify any specific steps or conditions that lead to the failure.
I hope these suggestions help you in troubleshooting the issue.
Best Regards,
Yash

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!