This is an automated email from the ASF dual-hosted git repository.
zhangyv 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 02f053baed test: Fix three flaky tests in ConnectionContextProxyTest
due to lock key order (#7802)
02f053baed is described below
commit 02f053baed3fabbe9ef9f97b96a5bcd9225f9417
Author: Xiaoyang Cai <[email protected]>
AuthorDate: Tue Nov 25 01:55:04 2025 -0600
test: Fix three flaky tests in ConnectionContextProxyTest due to lock key
order (#7802)
---
changes/en-us/2.x.md | 1 +
changes/zh-cn/2.x.md | 1 +
.../rm/datasource/ConnectionContextProxyTest.java | 52 +++++++++++++++++-----
3 files changed, 42 insertions(+), 12 deletions(-)
diff --git a/changes/en-us/2.x.md b/changes/en-us/2.x.md
index fe02ec7d40..cd056fad17 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
+- [[#7802](https://github.com/apache/incubator-seata/pull/7802)] Fix
non-deterministic in `ConnectionContextProxyTest`.
### refactor:
diff --git a/changes/zh-cn/2.x.md b/changes/zh-cn/2.x.md
index 3d6289812e..28e26d1b1e 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 正常运行
+- [[#7802](https://github.com/apache/incubator-seata/pull/7802)] 修复
`ConnectionContextProxyTest` 中锁键顺序不稳定导致的测试用例间歇性失败问题。
### refactor:
diff --git
a/rm-datasource/src/test/java/org/apache/seata/rm/datasource/ConnectionContextProxyTest.java
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/ConnectionContextProxyTest.java
index 538b989b17..e83eca88da 100644
---
a/rm-datasource/src/test/java/org/apache/seata/rm/datasource/ConnectionContextProxyTest.java
+++
b/rm-datasource/src/test/java/org/apache/seata/rm/datasource/ConnectionContextProxyTest.java
@@ -25,6 +25,7 @@ import org.junit.jupiter.api.Test;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Savepoint;
+import java.util.Arrays;
import java.util.List;
/**
@@ -34,13 +35,32 @@ import java.util.List;
public class ConnectionContextProxyTest {
ConnectionContext connectionContext = new ConnectionContext();
+ private static void assertLockKeysEqual(String expected, String actual) {
+ if (actual == null && expected == null) {
+ return;
+ }
+
+ Assertions.assertNotNull(actual, "Actual lock keys should not be
null.");
+ Assertions.assertNotNull(expected, "Expected lock keys should not be
null.");
+
+ // Split, sort, and compare the key arrays
+ String[] actualKeys = actual.split(";");
+ String[] expectedKeys = expected.split(";");
+
+ Arrays.sort(actualKeys);
+ Arrays.sort(expectedKeys);
+
+ Assertions.assertArrayEquals(expectedKeys, actualKeys, "The sorted
arrays of lock keys should be equal.");
+ }
+
@Test
public void testBuildLockKeys() throws Exception {
connectionContext.appendLockKey("abc");
connectionContext.appendLockKey("bcd");
Assertions.assertTrue(connectionContext.hasLockKey());
- Assertions.assertEquals(connectionContext.buildLockKeys(), "bcd;abc");
+
+ assertLockKeysEqual("abc;bcd", connectionContext.buildLockKeys());
}
@Test
@@ -104,15 +124,18 @@ public class ConnectionContextProxyTest {
connectionContext.appendUndoItem(new SQLUndoLog());
Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(),
"sp1-lock-key;sp3-lock-key");
connectionContext.removeSavepoint(sp3);
- Assertions.assertEquals(connectionContext.getUndoItems().size(), 1);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp1-lock-key");
+ Assertions.assertEquals(1, connectionContext.getUndoItems().size());
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(), "sp1-lock-key");
connectionContext.removeSavepoint(null);
- Assertions.assertEquals(connectionContext.getUndoItems().size(), 0);
- Assertions.assertNull(connectionContext.buildLockKeys());
+ Assertions.assertEquals(0, connectionContext.getUndoItems().size());
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(), null);
}
@Test
@@ -130,16 +153,21 @@ public class ConnectionContextProxyTest {
connectionContext.appendLockKey("sp3-lock-key");
connectionContext.appendUndoItem(new SQLUndoLog());
- Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+ Assertions.assertEquals(2, connectionContext.getUndoItems().size());
+
+ String expectedLockKeys = "sp1-lock-key;sp3-lock-key";
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(),
expectedLockKeys);
connectionContext.releaseSavepoint(sp3);
- Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+ Assertions.assertEquals(2, connectionContext.getUndoItems().size());
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(),
expectedLockKeys);
connectionContext.releaseSavepoint(null);
- Assertions.assertEquals(connectionContext.getUndoItems().size(), 2);
- Assertions.assertEquals(connectionContext.buildLockKeys(),
"sp3-lock-key;sp1-lock-key");
+ Assertions.assertEquals(2, connectionContext.getUndoItems().size());
+
+ assertLockKeysEqual(connectionContext.buildLockKeys(),
expectedLockKeys);
}
@AfterEach
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]