Skip to content

Commit

Permalink
Testing workflow on pull request added.
Browse files Browse the repository at this point in the history
  • Loading branch information
DamirDenis-Tudor committed Jan 16, 2025
1 parent ecb3565 commit dcf7bb9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 12 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pull-request-checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Testing

on:
pull_request:
types:
- opened
- synchronize

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Release in Maven Central
run: |
./gradlew test
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# ![KabbitMQ](https://github.com/user-attachments/assets/bc22917b-d6bd-4f34-8775-707e575677a0)abbitMQ

![Deployment Status](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/deployment.yml/badge.svg)
![Deployment Status](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/deployment.yml/badge.svg) | ![Pull Request Checks](https://github.com/DamirDenis-Tudor/ktor-server-rabbitmq/actions/workflows/pull-request-checks.yml/badge.svg)

## Overview

Expand Down
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,16 @@ dependencies {
tasks {
test {
useJUnitPlatform()
testLogging {
events("passed", "skipped", "failed")
showCauses = true
showStackTraces = true
}
}
}



tasks.register<Jar>("javadocJar") {
archiveClassifier.set("javadoc")
from(tasks["javadoc"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal fun Application.module() {
basicConsume {
autoAck = true
queue = "demo-queue"
deliveryCallback<String> { tag, message ->
deliverCallback<String> { tag, message ->

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class BasicConsumeBuilder(
}

@RabbitDslMarker
inline fun <reified T> deliveryCallback(crossinline callback: suspend (tag: Long, message: T) -> Unit) {
inline fun <reified T> deliverCallback(crossinline callback: suspend (tag: Long, message: T) -> Unit) {
connectionManager.coroutineScope.launch(dispatcher) {
receiverChannel.consumeAsFlow().collect { (deliveryTag, message) ->
callback(deliveryTag, Json.decodeFromString<T>(message))
Expand Down
27 changes: 25 additions & 2 deletions src/test/kotlin/InstallTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,38 @@ class InstallTests {
}

@Test
fun `test install rabbitmq with attempts and delay lower than 0`() = testApplication {
fun `test install rabbitmq with attemptDelay lower than 0`() = testApplication {
application{
assertFailsWith<IllegalArgumentException> {
install(RabbitMQ) {
attemptDelay = -1
}
}
}
}

@Test
fun `test install rabbitmq with connectionAttempts and delay lower than 0`() = testApplication {
application{
assertFailsWith<IllegalArgumentException> {
install(RabbitMQ) {
connectionAttempts = -1
}
}
}
}

@Test
fun `test install rabbitmq with dispatcherThreadPollSize and delay lower than 0`() = testApplication {
application{
assertFailsWith<IllegalArgumentException> {
install(RabbitMQ) {
dispatcherThreadPollSize = -1
}
}
}
}

@Test
fun `test install rabbitmq with uri empty`() = testApplication {
application{
Expand All @@ -67,9 +88,11 @@ class InstallTests {
application{
assertFailsWith<IllegalArgumentException> {
install(RabbitMQ) {
uri = ""
defaultConnectionName = ""
}
}
}
}


}
10 changes: 3 additions & 7 deletions src/test/kotlin/OperationsTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,12 @@ class OperationsTests {
}
}

assertEquals(messageCount { queue = "test-queue" }, 10)
assertEquals(messageCount { queue = "test-queue" }.getOrNull(), 10)

basicConsume {
queue = "test-queue"
autoAck = false
deliverCallback<Message> { tag, message ->
/* process message */
// ...

/* simulate something went wrong */
basicReject {
deliveryTag = tag
requeue = false
Expand All @@ -140,7 +136,7 @@ class OperationsTests {

Thread.sleep(2_000)

assertEquals(messageCount { queue = "dlq" }, 10)
assertEquals(messageCount { queue = "dlq" }.getOrNull(), 10)

basicConsume {
queue = "dlq"
Expand All @@ -152,7 +148,7 @@ class OperationsTests {

Thread.sleep(2_000)

assertEquals(messageCount { queue = "dlq" }, 0)
assertEquals(messageCount { queue = "dlq" }.getOrNull(), 0)
}
}
}
Expand Down

0 comments on commit dcf7bb9

Please sign in to comment.