-
Notifications
You must be signed in to change notification settings - Fork 411
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try all resolved IP addresses when client fails to connect (#2905)
* Try all resolved IP addresses when client fails to connect * Fix for Scala 2.12
- Loading branch information
1 parent
5ea81ef
commit baf5399
Showing
2 changed files
with
95 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
zio-http/jvm/src/test/scala/zio/http/ClientConnectionSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2021 - 2023 Sporta Technologies PVT LTD & the ZIO HTTP contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package zio.http | ||
|
||
import java.net.{InetAddress, UnknownHostException} | ||
|
||
import zio._ | ||
import zio.test.Assertion._ | ||
import zio.test.TestAspect._ | ||
import zio.test._ | ||
|
||
import zio.http.internal.{DynamicServer, HttpRunnableSpec, serverTestLayer} | ||
import zio.http.netty.NettyConfig | ||
|
||
object ClientConnectionSpec extends HttpRunnableSpec { | ||
|
||
private def tests = | ||
List( | ||
test("tries a different IP address when the connection fails") { | ||
val app = Handler.ok.toRoutes.deploy(Request()).map(_.status) | ||
assertZIO(app)(equalTo(Status.Ok)) | ||
} @@ nonFlaky(10), | ||
) | ||
|
||
override def spec = { | ||
suite("ClientConnectionSpec") { | ||
serve.as(tests) | ||
}.provideSome[DynamicServer & Server & Client](Scope.default) | ||
.provideShared( | ||
DynamicServer.live, | ||
serverTestLayer, | ||
Client.live, | ||
ZLayer.succeed(Client.Config.default.connectionTimeout(10.millis)), | ||
ZLayer.succeed(NettyConfig.defaultWithFastShutdown), | ||
ZLayer.succeed(TestResolver), | ||
) @@ sequential @@ withLiveClock @@ withLiveRandom | ||
} | ||
|
||
private object TestResolver extends DnsResolver { | ||
import scala.collection.compat._ | ||
|
||
override def resolve(host: String)(implicit trace: Trace): ZIO[Any, UnknownHostException, Chunk[InetAddress]] = { | ||
ZIO.succeed { | ||
Chunk.from((0 to 10).map { i => | ||
InetAddress.getByAddress(Array(127, 0, 0, i.toByte)) | ||
}) | ||
} | ||
} | ||
} | ||
} |