Anders
10/28/2025, 9:36 AMAleksei Tirman [JB]
11/03/2025, 9:03 AMAnders
11/03/2025, 9:06 AM@Execution(SAME_THREAD)
class InvoicingInvoiceDateTest : WithPostgreSQL(shouldPopulate = false) {
private val configuration = createApplicationConfig(RuntimeEnvironment("local"))
private lateinit var finalConfig: Config
@BeforeEach
fun setup() =
runTest(
timeout = 300.seconds,
) {
finalConfig =
configuration.copy(
database =
DatabaseConfig(
userName = postgres.username,
password = Masked(postgres.password),
host = postgres.host,
readonlyHost = postgres.host,
port = postgres.getMappedPort(5432),
db = postgres.databaseName,
schema = schema,
),
)
}
@Test
fun `preview one time plan`() =
runTest(
timeout = 300.seconds,
) {
val firstMonth =
now()
.withDayOfMonth(1)
.withHour(5)
val company =
readWrite.withTransaction {
InvoicingCompanyGenerator().generateCompany(
planSettings =
InvoicePlanSettingsSeed(
interval = NONE,
oneTimeDate = firstMonth,
),
)
}
testApplication {
application {
mainModule(
applicationConfig = finalConfig,
shouldSetRoutes = true,
)
val invoicingService by instance<InvoicingService>()
val planSettings =
readOnly.withSession {
invoicingService
.showPlanSettings(
companyId = company.companyId,
planId = company.sharedExpensesPlanId,
).revisions
.first()
}
val dueDate = planSettings.dueDate.toLong()
val previews =
readOnly.withSession {
invoicingService.preview(
companyId = company.companyId,
planId = company.sharedExpensesPlanId,
at = firstMonth,
)
}
previews.size.shouldBe(400, firstMonth.toGMTDate().toString())
previews.forEach {
it.invoiceDate.toLocalDate() shouldBe firstMonth.toLocalDate()
it.dueDate.toLocalDate() shouldBe
firstMonth
.plusDays(dueDate)
.toLocalDate()
}
}
}
}
WithPostgreSQL produces a schema for the test. Transactions and sessions run on IO. All functions are suspended.Anders
11/03/2025, 9:07 AMAnders
11/03/2025, 9:08 AM"-Dkotlinx.coroutines.test.default_timeout=300s"
but none of this works.Aleksei Tirman [JB]
11/04/2025, 7:14 AMAnders
11/04/2025, 8:54 AM@Test
fun `do the thing`() =
runTest(
timeout = 300.seconds,
) {
testApplication {
application {
delay(20000)
}
}
}Anders
11/04/2025, 8:54 AMAnders
11/04/2025, 8:54 AMAleksei Tirman [JB]
11/04/2025, 1:11 PMktor.application.startupTimeoutMillis property in the configuration:
testApplication {
environment {
config = MapApplicationConfig(
listOf("ktor.application.startupTimeoutMillis" to "300000")
)
}
application {
delay(20000)
}
}Anders
11/04/2025, 1:52 PMAleksei Tirman [JB]
11/04/2025, 2:04 PMAnders
11/04/2025, 2:12 PMAnders
11/04/2025, 3:17 PMAleksei Tirman [JB]
11/05/2025, 11:10 AMtestApplication function where the timeout will be set.Anders
11/05/2025, 11:13 AM