|
63 | 63 | import io.opentelemetry.api.trace.SpanContext; |
64 | 64 | import io.opentelemetry.context.Context; |
65 | 65 | import io.opentelemetry.instrumentation.openai.TestHelper; |
| 66 | +import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; |
66 | 67 | import java.util.ArrayList; |
67 | 68 | import java.util.Arrays; |
68 | 69 | import java.util.Collections; |
|
73 | 74 | import java.util.concurrent.CompletionException; |
74 | 75 | import java.util.stream.Collectors; |
75 | 76 | import org.junit.jupiter.api.Test; |
| 77 | +import org.junit.jupiter.api.extension.RegisterExtension; |
76 | 78 |
|
77 | 79 | public abstract class AbstractChatTest extends AbstractOpenAiTest { |
| 80 | + |
78 | 81 | protected static final AttributeKey<String> EVENT_NAME = AttributeKey.stringKey("event.name"); |
79 | 82 |
|
80 | 83 | protected static final String TEST_CHAT_MODEL = "gpt-4o-mini"; |
81 | 84 | protected static final String TEST_CHAT_RESPONSE_MODEL = "gpt-4o-mini-2024-07-18"; |
82 | 85 | protected static final String TEST_CHAT_INPUT = |
83 | 86 | "Answer in up to 3 words: Which ocean contains Bouvet Island?"; |
84 | 87 |
|
| 88 | + @RegisterExtension static final AutoCleanupExtension cleanup = AutoCleanupExtension.create(); |
| 89 | + |
85 | 90 | protected final ChatCompletion doCompletions(ChatCompletionCreateParams params) { |
86 | 91 | return doCompletions(params, getClient(), getClientAsync()); |
87 | 92 | } |
@@ -878,6 +883,8 @@ void connectionError() { |
878 | 883 | .apiKey("testing") |
879 | 884 | .maxRetries(0) |
880 | 885 | .build()); |
| 886 | + cleanup.deferCleanup(client::close); |
| 887 | + cleanup.deferCleanup(clientAsync::close); |
881 | 888 |
|
882 | 889 | ChatCompletionCreateParams params = |
883 | 890 | ChatCompletionCreateParams.builder() |
@@ -1583,6 +1590,8 @@ void streamConnectionError() { |
1583 | 1590 | .apiKey("testing") |
1584 | 1591 | .maxRetries(0) |
1585 | 1592 | .build()); |
| 1593 | + cleanup.deferCleanup(client::close); |
| 1594 | + cleanup.deferCleanup(clientAsync::close); |
1586 | 1595 |
|
1587 | 1596 | ChatCompletionCreateParams params = |
1588 | 1597 | ChatCompletionCreateParams.builder() |
|
0 commit comments