Skip to content

Commit

Permalink
KTOR-7995 Move test-server to a separate included build
Browse files Browse the repository at this point in the history
  • Loading branch information
osipxd committed Dec 27, 2024
1 parent 29245c8 commit a631b94
Show file tree
Hide file tree
Showing 52 changed files with 206 additions and 129 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ val disabledExplicitApiModeProjects = listOf(
apply(from = "gradle/compatibility.gradle")

plugins {
id("test-server") apply false
alias(libs.plugins.dokka) apply false
alias(libs.plugins.binaryCompatibilityValidator)
conventions.gradleDoctor
Expand Down
22 changes: 0 additions & 22 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

plugins {
`kotlin-dsl`
// Serialization version should be aligned with the Kotlin version embedded in Gradle
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
kotlin("plugin.serialization") version embeddedKotlinVersion
}

dependencies {
Expand All @@ -16,25 +13,6 @@ dependencies {
implementation(libs.kotlinter)
implementation(libs.develocity)
implementation(libs.gradleDoctor)

implementation(libs.ktor.server.default.headers)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.jetty)
implementation(libs.ktor.server.websockets)
implementation(libs.ktor.server.auth)
implementation(libs.ktor.server.caching.headers)
implementation(libs.ktor.server.conditional.headers)
implementation(libs.ktor.server.compression)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.server.status.pages)
implementation(libs.ktor.serialization.kotlinx)
implementation(libs.ktor.network.tls.certificates)
implementation(libs.ktor.utils)

implementation(libs.kotlinx.serialization.json)
implementation(libs.logback.classic)
implementation(libs.tomlj)
implementation(libs.kotlinx.atomicfu.gradlePlugin)

// A hack to make version catalogs accessible from buildSrc sources
Expand Down
9 changes: 0 additions & 9 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,13 @@ pluginManagement {
}

plugins {
id("org.gradle.toolchains.foojay-resolver-convention")
id("conventions-dependency-resolution-management")
}

dependencyResolutionManagement {
// Additional repositories for buildSrc dependencies
@Suppress("UnstableApiUsage")
repositories {
gradlePluginPortal()

exclusiveContent {
forRepository {
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap") { name = "KtorEAP" }
}
filter { includeGroup("io.ktor") }
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ pluginManagement {
}

mavenLocal()

exclusiveContent {
forRepository {
maven("https://maven.pkg.jetbrains.space/public/p/ktor/eap") { name = "KtorEAP" }
}
filter { includeVersionByRegex("io.ktor", ".+", ".+-eap-\\d+") }
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion ktor-client/ktor-client-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

import org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest

apply<test.server.TestServerPlugin>()
plugins {
id("test-server")
}

kotlin.sourceSets {
jvmMain {
Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-apache/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

description = "Apache backend for ktor http client"

apply<test.server.TestServerPlugin>()
plugins {
id("test-server")
}

kotlin.sourceSets {
jvmMain {
Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-apache5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

description = "Apache backend for ktor http client"

apply<test.server.TestServerPlugin>()
plugins {
id("test-server")
}

kotlin.sourceSets {
jvmMain {
Expand Down
4 changes: 3 additions & 1 deletion ktor-client/ktor-client-cio/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

description = "CIO backend for ktor http client"

apply<test.server.TestServerPlugin>()
plugins {
id("test-server")
}

kotlin {
sourceSets {
Expand Down
5 changes: 4 additions & 1 deletion ktor-client/ktor-client-curl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

val paths = listOf(
"/opt/homebrew/opt/curl/include/",
Expand All @@ -19,6 +21,7 @@ val paths = listOf(

plugins {
id("kotlinx-serialization")
id("test-server")
}

kotlin {
Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-darwin-legacy/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("test-server")
}

kotlin {
sourceSets {
Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-darwin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("test-server")
}

kotlin {

Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-java/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("test-server")
}

kotlin.sourceSets {
jvmMain {
Expand Down
8 changes: 7 additions & 1 deletion ktor-client/ktor-client-okhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("test-server")
}

kotlin.sourceSets {
jvmMain {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import test.server.*

description = "Ktor client Auth support"

apply<TestServerPlugin>()
plugins {
id("test-server")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

apply<test.server.TestServerPlugin>()
plugins {
id("test-server")
}

kotlin.sourceSets {
jvmTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ description = "Ktor client JSON support"

plugins {
id("kotlinx-serialization")
id("test-server")
}

apply<test.server.TestServerPlugin>()

kotlin {
sourceSets {
// This is a workaround for https://youtrack.jetbrains.com/issue/KT-39037
Expand Down
5 changes: 1 addition & 4 deletions ktor-client/ktor-client-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import test.server.TestServerPlugin

description = "Common tests for client"

plugins {
id("kotlinx-serialization")
id("test-server")
}

apply<TestServerPlugin>()

kotlin.sourceSets {
commonMain {
dependencies {
Expand Down
6 changes: 4 additions & 2 deletions ktor-client/ktor-client-winhttp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@

apply<test.server.TestServerPlugin>()
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
id("kotlinx-serialization")
id("test-server")
}

kotlin {
Expand Down
3 changes: 3 additions & 0 deletions ktor-test-server/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ktor-test-server

The server used for integration tests of Ktor itself.
36 changes: 36 additions & 0 deletions ktor-test-server/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

plugins {
`kotlin-dsl`
// Serialization version should be aligned with the Kotlin version embedded in Gradle
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
kotlin("plugin.serialization") version embeddedKotlinVersion
}

dependencies {
implementation(libs.ktor.server.default.headers)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.cio)
implementation(libs.ktor.server.jetty)
implementation(libs.ktor.server.websockets)
implementation(libs.ktor.server.auth)
implementation(libs.ktor.server.caching.headers)
implementation(libs.ktor.server.conditional.headers)
implementation(libs.ktor.server.compression)
implementation(libs.ktor.server.content.negotiation)
implementation(libs.ktor.server.status.pages)
implementation(libs.ktor.serialization.kotlinx)
implementation(libs.ktor.network.tls.certificates)
implementation(libs.ktor.utils)

implementation(libs.kotlinx.serialization.json)
implementation(libs.logback.classic)
implementation(libs.tomlj)
}

// Should be synced with gradle/gradle-daemon-jvm.properties
kotlin {
jvmToolchain(21)
}
13 changes: 13 additions & 0 deletions ktor-test-server/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

pluginManagement {
includeBuild("../gradle-settings-conventions")
}

plugins {
id("conventions-dependency-resolution-management")
}

rootProject.name = "ktor-test-server"
13 changes: 13 additions & 0 deletions ktor-test-server/src/main/kotlin/test-server.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

import test.server.TestServerService

val testServerService = TestServerService.registerIfAbsent(project)

tasks.withType<AbstractTestTask>().configureEach {
usesService(testServerService)
// Trigger server start if it is not started yet
doFirst("start test server") { testServerService.get() }
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package test.server

import io.ktor.client.tests.utils.tests.*
import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.plugins.contentnegotiation.*
import io.ktor.server.plugins.defaultheaders.*
import io.ktor.server.plugins.statuspages.*
import io.ktor.server.request.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
* Copyright 2014-2024 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/

package test.server
Expand All @@ -8,7 +8,6 @@ import io.ktor.http.*
import io.ktor.http.content.*
import io.ktor.util.*
import io.ktor.utils.io.*
import io.ktor.utils.io.charsets.*
import io.ktor.utils.io.core.*

fun makeArray(size: Int): ByteArray = ByteArray(size) { it.toByte() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import io.ktor.network.tls.certificates.*
import io.ktor.server.cio.*
import io.ktor.server.engine.*
import io.ktor.server.jetty.jakarta.*
import test.server.tests.*
import java.io.*
import java.util.concurrent.*
import test.server.tests.CloseableGroup
import test.server.tests.tcpServerHandler
import java.io.Closeable
import java.io.File
import java.util.concurrent.TimeUnit

const val TEST_SERVER: String = "http://127.0.0.1:8080"

Expand Down
Loading

0 comments on commit a631b94

Please sign in to comment.