Skip to content

Commit 0c25eef

Browse files
committed
Update the concurrency test
1 parent d6e4fa4 commit 0c25eef

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

sqllin-dsl/src/commonTest/kotlin/com/ctrip/sqllin/dsl/CommonBasicTest.kt

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.ASC
2424
import com.ctrip.sqllin.dsl.sql.clause.OrderByWay.DESC
2525
import com.ctrip.sqllin.dsl.sql.statement.SelectStatement
2626
import kotlinx.coroutines.Dispatchers
27+
import kotlinx.coroutines.delay
2728
import kotlinx.coroutines.launch
2829
import kotlinx.coroutines.runBlocking
2930
import kotlin.test.assertEquals
@@ -374,36 +375,32 @@ class CommonBasicTest(private val path: DatabasePath) {
374375
val book1 = Book(name = "The Da Vinci Code", author = "Dan Brown", pages = 454, price = 16.96)
375376
val book2 = Book(name = "The Lost Symbol", author = "Dan Brown", pages = 510, price = 19.95)
376377
launch {
377-
var statement: SelectStatement<Book>? = null
378+
lateinit var statement: SelectStatement<Book>
378379
database suspendedScope {
379380
statement = BookTable { table ->
380381
table INSERT listOf(book1, book2)
381382
table SELECT X
382383
}
383384
}
384-
385-
launch {
386-
val book1NewPrice = 18.96
387-
val book2NewPrice = 21.95
388-
val newBook1 = Book(name = "The Da Vinci Code", author = "Dan Brown", pages = 454, price = book1NewPrice)
389-
val newBook2 = Book(name = "The Lost Symbol", author = "Dan Brown", pages = 510, price = book2NewPrice)
390-
var newResult: SelectStatement<Book>? = null
391-
database suspendedScope {
392-
newResult = transaction {
393-
BookTable { table ->
394-
table UPDATE SET { price = book1NewPrice } WHERE (name EQ book1.name AND (price EQ book1.price))
395-
table UPDATE SET { price = book2NewPrice } WHERE (name EQ book2.name AND (price EQ book2.price))
396-
table SELECT X
397-
}
385+
assertEquals(true, statement.getResults().any { it == book1 })
386+
assertEquals(true, statement.getResults().any { it == book2 })
387+
}
388+
launch {
389+
val book1NewPrice = 18.96
390+
val book2NewPrice = 21.95
391+
val newBook1 = Book(name = "The Da Vinci Code", author = "Dan Brown", pages = 454, price = book1NewPrice)
392+
val newBook2 = Book(name = "The Lost Symbol", author = "Dan Brown", pages = 510, price = book2NewPrice)
393+
lateinit var statement: SelectStatement<Book>
394+
database suspendedScope {
395+
statement = transaction {
396+
BookTable { table ->
397+
table INSERT listOf(newBook1, newBook2)
398+
table SELECT X
398399
}
399400
}
400-
401-
assertEquals(true, newResult!!.getResults().any { it == newBook1 })
402-
assertEquals(true, newResult!!.getResults().any { it == newBook2 })
403401
}
404-
405-
assertEquals(true, statement!!.getResults().any { it == book1 })
406-
assertEquals(true, statement!!.getResults().any { it == book2 })
402+
assertEquals(true, statement.getResults().any { it == newBook1 })
403+
assertEquals(true, statement.getResults().any { it == newBook2 })
407404
}
408405
}
409406
}
@@ -441,12 +438,12 @@ class CommonBasicTest(private val path: DatabasePath) {
441438
lateinit var selectStatement: SelectStatement<NullTester>
442439
// INSERT & SELECT
443440
database {
444-
NullTesterTable { table ->
441+
selectStatement = NullTesterTable { table ->
445442
table INSERT listOf(
446443
NullTester(null, null, null),
447444
NullTester(8, "888", 8.8),
448445
)
449-
selectStatement = table SELECT X
446+
table SELECT X
450447
}
451448
}
452449

@@ -467,9 +464,9 @@ class CommonBasicTest(private val path: DatabasePath) {
467464

468465
// UPDATE & SELECT
469466
database {
470-
NullTesterTable { table ->
467+
selectStatement = NullTesterTable { table ->
471468
table UPDATE SET { paramString = null } WHERE (paramDouble EQ 8.8)
472-
selectStatement = table SELECT WHERE (paramInt NEQ null)
469+
table SELECT WHERE (paramInt NEQ null)
473470
}
474471
}
475472
val result1 = selectStatement.getResults().first()
@@ -480,9 +477,9 @@ class CommonBasicTest(private val path: DatabasePath) {
480477

481478
// DELETE & SELECT
482479
database {
483-
NullTesterTable { table ->
480+
selectStatement = NullTesterTable { table ->
484481
table DELETE WHERE (paramInt EQ null OR (paramDouble EQ null))
485-
selectStatement = table SELECT X
482+
table SELECT X
486483
}
487484
}
488485
val result2 = selectStatement.getResults().first()

0 commit comments

Comments
 (0)