Skip to content

Commit 78a128f

Browse files
committed
🔧 [shared] 移除 OptimizedSnowflakeTest 中的 DisplayName 注解并优化测试逻辑
- 移除 `DisplayName` 注解 - 优化 `ClockBackwardTests` 中的序列溢出测试逻辑 - 确保生成的 ID 唯一且递增
1 parent cf5b799 commit 78a128f

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

shared/src/test/kotlin/io/github/truenine/composeserver/generator/OptimizedSnowflakeTest.kt

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ import kotlin.test.assertEquals
99
import kotlin.test.assertNotEquals
1010
import kotlin.test.assertTrue
1111
import org.junit.jupiter.api.BeforeEach
12-
import org.junit.jupiter.api.DisplayName
1312
import org.junit.jupiter.api.Nested
1413
import org.junit.jupiter.api.Test
1514
import org.junit.jupiter.api.assertAll
1615
import org.junit.jupiter.api.assertDoesNotThrow
1716
import org.junit.jupiter.api.assertThrows
1817

19-
@DisplayName("Optimized SynchronizedSimpleSnowflake Tests")
2018
class OptimizedSnowflakeTest {
2119
private lateinit var snowflake: SynchronizedSimpleSnowflake
2220
private val startTimeStamp = 1577836800000L // 2020-01-01 00:00:00 UTC
@@ -27,7 +25,6 @@ class OptimizedSnowflakeTest {
2725
}
2826

2927
@Nested
30-
@DisplayName("Constructor Parameter Validation Tests")
3128
inner class ConstructorValidationTests {
3229

3330
@Test
@@ -93,7 +90,6 @@ class OptimizedSnowflakeTest {
9390
}
9491

9592
@Nested
96-
@DisplayName("ID Generation Tests")
9793
inner class IdGenerationTests {
9894

9995
@Test
@@ -156,7 +152,6 @@ class OptimizedSnowflakeTest {
156152
}
157153

158154
@Nested
159-
@DisplayName("Clock Backward Handling Tests")
160155
inner class ClockBackwardTests {
161156

162157
@Test
@@ -246,26 +241,26 @@ class OptimizedSnowflakeTest {
246241
SynchronizedSimpleSnowflake(
247242
workId = 1L,
248243
datacenterId = 1L,
249-
sequence = 4094L, // Close to max to trigger overflow
244+
sequence = 4094L, // Start with sequence 4094
250245
startTimeStamp = startTimeStamp,
251246
)
252247

253-
val id1 = testSnowflake.next()
254-
val id2 = testSnowflake.next()
255-
val id3 = testSnowflake.next()
256-
257-
// All IDs should be unique and increasing
258-
assertTrue(id2 > id1, "Second ID should be greater than first")
259-
assertTrue(id3 > id2, "Third ID should be greater than second")
248+
// Generate IDs rapidly in the same millisecond to trigger sequence overflow
249+
val ids = mutableListOf<Long>()
250+
repeat(10) { ids.add(testSnowflake.next()) }
260251

261252
// Verify overflow count increased
262253
val stats = testSnowflake.getStatistics()
263-
assertTrue(stats.sequenceOverflowCount > 0, "Should have sequence overflow")
254+
assertTrue(stats.sequenceOverflowCount > 0, "Should have sequence overflow after generating multiple IDs rapidly")
255+
256+
// All IDs should be unique and increasing
257+
for (i in 1 until ids.size) {
258+
assertTrue(ids[i] > ids[i - 1], "ID at index $i should be greater than previous ID")
259+
}
264260
}
265261
}
266262

267263
@Nested
268-
@DisplayName("Concurrency Tests")
269264
inner class ConcurrencyTests {
270265

271266
@Test
@@ -347,7 +342,6 @@ class OptimizedSnowflakeTest {
347342
}
348343

349344
@Nested
350-
@DisplayName("Statistics Tests")
351345
inner class StatisticsTests {
352346

353347
@Test
@@ -384,7 +378,6 @@ class OptimizedSnowflakeTest {
384378
}
385379

386380
@Nested
387-
@DisplayName("Edge Cases and Boundary Tests")
388381
inner class EdgeCaseTests {
389382

390383
@Test
@@ -429,7 +422,6 @@ class OptimizedSnowflakeTest {
429422
}
430423

431424
@Nested
432-
@DisplayName("Statistics Data Class Tests")
433425
inner class StatisticsDataClassTests {
434426

435427
@Test

0 commit comments

Comments
 (0)