Skip to content

Commit d1fee9e

Browse files
committed
Add failed smoke test logging
1 parent 8cc53c3 commit d1fee9e

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ object RuntimeTypes {
116116

117117
object SmokeTests : RuntimeTypePackage(KotlinDependency.CORE, "smoketests") {
118118
val exitProcess = symbol("exitProcess")
119+
val printExceptionStackTrace = symbol("printExceptionStackTrace")
119120
}
120121

121122
object Collections : RuntimeTypePackage(KotlinDependency.CORE, "collections") {

codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/smoketests/SmokeTestsRunnerGenerator.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class SmokeTestsRunnerGenerator(
236236
testCase.expectation.isFailure,
237237
writer,
238238
)
239+
writer.write("if (!success) #T(e)", RuntimeTypes.Core.SmokeTests.printExceptionStackTrace)
239240
writer.write("if (!success) exitCode = 1")
240241
}
241242

codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/smoketests/SmokeTestsRunnerGeneratorTest.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ class SmokeTestsRunnerGeneratorTest {
122122
val success = e is SmokeTestsSuccessException
123123
val status = if (success) "ok" else "not ok"
124124
println("${'$'}status Test SuccessTest - no error expected from service ")
125+
if (!success) printExceptionStackTrace(e)
125126
if (!success) exitCode = 1
126127
}
127128
}
@@ -155,6 +156,7 @@ class SmokeTestsRunnerGeneratorTest {
155156
val success = e is InvalidMessageError
156157
val status = if (success) "ok" else "not ok"
157158
println("${'$'}status Test InvalidMessageErrorTest - error expected from service ")
159+
if (!success) printExceptionStackTrace(e)
158160
if (!success) exitCode = 1
159161
}
160162
}
@@ -189,6 +191,7 @@ class SmokeTestsRunnerGeneratorTest {
189191
val success = e is SmokeTestsFailureException
190192
val status = if (success) "ok" else "not ok"
191193
println("${'$'}status Test FailureTest - error expected from service ")
194+
if (!success) printExceptionStackTrace(e)
192195
if (!success) exitCode = 1
193196
}
194197
}

runtime/protocol/http-client/api/http-client.api

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public final class aws/smithy/kotlin/runtime/http/interceptors/ResponseLengthVal
425425
}
426426

427427
public final class aws/smithy/kotlin/runtime/http/interceptors/SmokeTestsFailureException : java/lang/Exception {
428-
public fun <init> ()V
428+
public fun <init> (Ljava/lang/String;)V
429429
}
430430

431431
public final class aws/smithy/kotlin/runtime/http/interceptors/SmokeTestsInterceptor : aws/smithy/kotlin/runtime/client/Interceptor {
@@ -452,7 +452,7 @@ public final class aws/smithy/kotlin/runtime/http/interceptors/SmokeTestsInterce
452452
}
453453

454454
public final class aws/smithy/kotlin/runtime/http/interceptors/SmokeTestsSuccessException : java/lang/Exception {
455-
public fun <init> ()V
455+
public fun <init> (Ljava/lang/String;)V
456456
}
457457

458458
public final class aws/smithy/kotlin/runtime/http/middleware/DefaultValidateResponse : aws/smithy/kotlin/runtime/http/operation/ReceiveMiddleware {

runtime/protocol/http-client/common/src/aws/smithy/kotlin/runtime/http/interceptors/SmokeTestsInterceptor.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ public class SmokeTestsInterceptor : HttpInterceptor {
1616
override fun readBeforeDeserialization(context: ProtocolResponseInterceptorContext<Any, HttpRequest, HttpResponse>) {
1717
val status = context.protocolResponse.status.value
1818
when (status) {
19-
in 400..599 -> throw SmokeTestsFailureException()
20-
in 200..299 -> throw SmokeTestsSuccessException()
21-
else -> throw SmokeTestsUnexpectedException()
19+
in 400..599 -> throw SmokeTestsFailureException("Smoke test failed with HTTP status code: $status")
20+
in 200..299 -> throw SmokeTestsSuccessException("Smoke test succeeded with HTTP status code: $status")
21+
else -> throw SmokeTestsUnexpectedException("Smoke test returned HTTP status code: $status")
2222
}
2323
}
2424
}
2525

26-
@InternalApi public class SmokeTestsFailureException : Exception()
26+
@InternalApi public class SmokeTestsFailureException(message: String) : Exception(message)
2727

28-
@InternalApi public class SmokeTestsSuccessException : Exception()
29-
private class SmokeTestsUnexpectedException : Exception()
28+
@InternalApi public class SmokeTestsSuccessException(message: String) : Exception(message)
29+
private class SmokeTestsUnexpectedException(message: String) : Exception(message)

runtime/runtime-core/api/runtime-core.api

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,6 +2048,10 @@ public final class aws/smithy/kotlin/runtime/smoketests/SmokeTestsFunctionsJVMKt
20482048
public static final fun exitProcess (I)Ljava/lang/Void;
20492049
}
20502050

2051+
public final class aws/smithy/kotlin/runtime/smoketests/SmokeTestsFunctionsKt {
2052+
public static final fun printExceptionStackTrace (Ljava/lang/Exception;)V
2053+
}
2054+
20512055
public final class aws/smithy/kotlin/runtime/text/Scanner {
20522056
public fun <init> (Ljava/lang/String;)V
20532057
public final fun getText ()Ljava/lang/String;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
11
package aws.smithy.kotlin.runtime.smoketests
22

33
public expect fun exitProcess(status: Int): Nothing
4+
5+
/**
6+
* Prints an exceptions stack trace using test anything protocol (TAP) format e.g.
7+
*
8+
* #java.lang.ArithmeticException: / by zero
9+
* # at FileKt.main(File.kt:3)
10+
* # at FileKt.main(File.kt)
11+
* # at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
12+
* # at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
13+
* # at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
14+
* # at java.base/java.lang.reflect.Method.invoke(Unknown Source)
15+
* # at executors.JavaRunnerExecutor$Companion.main(JavaRunnerExecutor.kt:27)
16+
* # at executors.JavaRunnerExecutor.main(JavaRunnerExecutor.kt)
17+
*/
18+
public fun printExceptionStackTrace(exception: Exception): Unit =
19+
println(exception.stackTraceToString().split("\n").joinToString("\n") { "#$it" })

0 commit comments

Comments
 (0)