This is an automated email from the ASF dual-hosted git repository.
maple pushed a commit to branch 2.x
in repository https://gitbox.apache.org/repos/asf/incubator-seata.git
The following commit(s) were added to refs/heads/2.x by this push:
new 196bd34df5 test: Fix flaky testToStringAndCycleDependency in
StringUtilsTest (#7800)
196bd34df5 is described below
commit 196bd34df53da70899b7b45ca032878c64caf20a
Author: Xiaoyang Cai <[email protected]>
AuthorDate: Tue Nov 25 09:29:09 2025 -0600
test: Fix flaky testToStringAndCycleDependency in StringUtilsTest (#7800)
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
.../apache/seata/common/util/StringUtilsTest.java | 37 +++++++++++++++++-----
3 files changed, 31 insertions(+), 8 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index cd056fad17..88b67830e8 100644
--- a/changes/en-us/2.x.md
+++ b/changes/en-us/2.x.md
@@ -119,6 +119,7 @@ Add changes here for all PR submitted to the 2.x branch.
- [[#7727](https://github.com/apache/incubator-seata/pull/7727)] add some UT
for compatible module
- [[#7803](https://github.com/apache/incubator-seata/pull/7803)] Fix flakiness
in `DataCompareUtilsTest` caused by non-deterministic Map key iteration order.
- [[#7804](https://github.com/apache/incubator-seata/pull/7804)] fix
testXARollbackWithResourceLock() to ensure ci runs normally
+- [[#7800](https://github.com/apache/incubator-seata/pull/7800)] fix
non-deterministic in StringUtilsTest#testToStringAndCycleDependency
- [[#7802](https://github.com/apache/incubator-seata/pull/7802)] Fix
non-deterministic in `ConnectionContextProxyTest`.
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 28e26d1b1e..9bbdf69f3a 100644
--- a/changes/zh-cn/2.x.md
+++ b/changes/zh-cn/2.x.md
@@ -118,6 +118,7 @@
- [[#7727](https://github.com/apache/incubator-seata/pull/7727)] 为 compatible
模块添加单测
- [[#7803](https://github.com/apache/incubator-seata/pull/7803)] 修复
`DataCompareUtilsTest` 中因键迭代顺序不稳定导致的测试用例间歇性失败问题。
- [[#7804](https://github.com/apache/incubator-seata/pull/7804)] 修复
testXARollbackWithResourceLock() 以确保 CI 正常运行
+- [[#7800](https://github.com/apache/incubator-seata/pull/7800)] 修复
`StringUtilsTest.testToStringAndCycleDependency` 因反射字段顺序不稳定导致的测试用例间歇性失败问题
- [[#7802](https://github.com/apache/incubator-seata/pull/7802)] 修复
`ConnectionContextProxyTest` 中锁键顺序不稳定导致的测试用例间歇性失败问题。
diff --git
a/common/src/test/java/org/apache/seata/common/util/StringUtilsTest.java
b/common/src/test/java/org/apache/seata/common/util/StringUtilsTest.java
index f2219d3604..6952aed7c9 100644
--- a/common/src/test/java/org/apache/seata/common/util/StringUtilsTest.java
+++ b/common/src/test/java/org/apache/seata/common/util/StringUtilsTest.java
@@ -282,29 +282,50 @@ public class StringUtilsTest {
Assertions.assertFalse(CycleDependencyHandler.isStarting());
// case: Object
- Assertions.assertEquals("CycleDependency(s=\"a\", obj=null)",
StringUtils.toString(CycleDependency.A));
+ String resultCycleDependencyA =
StringUtils.toString(CycleDependency.A);
+
Assertions.assertTrue(resultCycleDependencyA.startsWith("CycleDependency("));
+ Assertions.assertTrue(resultCycleDependencyA.endsWith(")"));
+ Assertions.assertTrue(resultCycleDependencyA.contains("s=\"a\""));
+ Assertions.assertTrue(resultCycleDependencyA.contains("obj=null"));
// case: Object, and cycle dependency
CycleDependency obj = new CycleDependency("c");
obj.setObj(obj);
- Assertions.assertEquals("CycleDependency(s=\"c\", obj=(this
CycleDependency))", StringUtils.toString(obj));
+ String resultCycleDependencyObj = StringUtils.toString(obj);
+
Assertions.assertTrue(resultCycleDependencyObj.startsWith("CycleDependency("));
+ Assertions.assertTrue(resultCycleDependencyObj.endsWith(")"));
+ Assertions.assertTrue(resultCycleDependencyObj.contains("s=\"c\""));
+ Assertions.assertTrue(resultCycleDependencyObj.contains("obj=(this
CycleDependency)"));
// case: Object
CycleDependency obj2 = new CycleDependency("d");
obj.setObj(obj2);
- Assertions.assertEquals(
- "CycleDependency(s=\"c\", obj=CycleDependency(s=\"d\",
obj=null))", StringUtils.toString(obj));
+ String actualCD = StringUtils.toString(obj);
+ String expectedCanonicalCD = "CycleDependency(s=\"c\",
obj=CycleDependency(s=\"d\", obj=null))";
+ String expectedAlternateCD =
"CycleDependency(obj=CycleDependency(obj=null, s=\"d\"), s=\"c\")";
+ Assertions.assertTrue(
+ expectedCanonicalCD.equals(actualCD) ||
expectedAlternateCD.equals(actualCD),
+ "Unexpected String representation for nested CycleDependency.
Actual: " + actualCD);
// case: Object, and cycle dependency
TestClass a = new TestClass();
a.setObj(a);
- Assertions.assertEquals("TestClass(obj=(this TestClass), s=null)",
StringUtils.toString(a));
+ String resultA = StringUtils.toString(a); // check for the presence of
field-value pairs regardless of order
+ Assertions.assertTrue(resultA.startsWith("TestClass("));
+ Assertions.assertTrue(resultA.endsWith(")"));
+ Assertions.assertTrue(resultA.contains("obj=(this TestClass)"));
+ Assertions.assertTrue(resultA.contains("s=null"));
// case: Object, and cycle dependency(deep case)
TestClass b = new TestClass();
TestClass c = new TestClass();
b.setObj(c);
c.setObj(a);
a.setObj(b);
- Assertions.assertEquals(
- "TestClass(obj=TestClass(obj=TestClass(obj=(ref TestClass),
s=null), s=null), s=null)",
- StringUtils.toString(a));
+ String actual = StringUtils.toString(a);
+ String expectedCanonical =
+ "TestClass(obj=TestClass(obj=TestClass(obj=(ref TestClass),
s=null), s=null), s=null)";
+ String expectedAlternate =
+ "TestClass(s=null, obj=TestClass(s=null, obj=TestClass(s=null,
obj=(ref TestClass))))";
+ Assertions.assertTrue(
+ expectedCanonical.equals(actual) ||
expectedAlternate.equals(actual),
+ "Unexpected String representation for deep cycle dependency.
Actual: " + actual);
// case: anonymous class from an interface
Object anonymousObj = new TestInterface() {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]