Skip to content

Commit effe6d1

Browse files
committed
failed connections to database test and bugfix
1 parent 9b950fa commit effe6d1

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

src/main/scala/io/vertx/asyncsql/database/pool/AsyncConnectionPool.scala

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ trait AsyncConnectionPool[ConnType <: Connection] {
3939
giveBack(c)
4040
p.failure(ex)
4141
}
42+
} recover {
43+
case ex => p.failure(ex)
4244
}
4345
p.future
4446
}

src/test/scala/io/vertx/asyncsql/test/BaseVertxIntegrationTest.scala

+6-2
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,18 @@ import org.vertx.testtools.VertxAssert.{ assertEquals, fail, testComplete }
1010

1111
trait BaseVertxIntegrationTest { this: TestVerticle =>
1212
val address: String
13+
type not[T] = T => Nothing
1314

1415
protected def asyncTest[X](fn: => Future[X]): Future[Unit] = {
1516
fn recover {
1617
case x =>
1718
logger.error("async fail in test code!", x)
1819
fail("Something failed asynchronously: " + x.getClass() + x.getMessage())
19-
} map { _ =>
20-
testComplete
20+
} map {
21+
case f: Future[_] =>
22+
logger.warn("test code most likely wrong! returns Future[Future[_]]")
23+
testComplete
24+
case _ => testComplete
2125
}
2226
}
2327

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.vertx.asyncsql.test.postgresql
2+
3+
import org.junit.Test
4+
import org.vertx.scala.core.json._
5+
import org.vertx.testtools.VertxAssert._
6+
import io.vertx.asyncsql.test.{ BaseSqlTests, SqlTestVerticle }
7+
import scala.concurrent.Future
8+
9+
class BadlyConfiguredPostgreSqlTest extends SqlTestVerticle {
10+
11+
val address = "campudus.asyncdb"
12+
val config = Json.obj("address" -> address, "database" -> "nonexistent")
13+
14+
override def getConfig = config
15+
16+
@Test
17+
def testNonExistentDatabase(): Unit = asyncTest {
18+
expectError(raw("SELECT 0")) map { reply =>
19+
assertTrue(reply.getString("message").contains("nonexistent"))
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)