-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue_2212 update client proxy settings #2336
Conversation
) | ||
.provide( | ||
ZLayer.succeed(ZClient.Config.default), | ||
proxied(proxy), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamgfraser I don't know how to reuse ZClient.customized
or using NettyClientDriver.live
to create proxy ZClient. With this I ended up with 2 ClientDriver
s.
Need your feedback on refactor/improve this unit test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rajcspsg I think it would be helpful to take a look at the text below proxy respond Ok
and think about the user feature we are trying to implement and how the test could be rewritten to use our functionality.
In that test, the client is created with Client.customized
, which requires a Config
, and the Config
is customized to use a proxy by using the proxy
operator on Config
.
The functionality we are trying to implement is to allow the user to customize the client locally. So instead of having to provide the proxy at the very top of the application the user should be able to specify it right before they call an operator on the client or at any other level.
This means that instead of providing Client.customized
the user should be able to provide Client.default
or leave the Config
as Config.default
.
Then in your test you can call ZIO.service[Client]
to access the client, call your new proxy
operator on Client
to get a customized client that uses the proxy and then get the same result as in the original test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamgfraser I updated the code. Could you please take a look again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamgfraser could you please take at my code changes?
Codecov ReportPatch coverage:
❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more. Additional details and impacted files@@ Coverage Diff @@
## main #2336 +/- ##
==========================================
+ Coverage 63.00% 63.01% +0.01%
==========================================
Files 136 136
Lines 7004 7009 +5
Branches 1210 1222 +12
==========================================
+ Hits 4413 4417 +4
- Misses 2591 2592 +1
☔ View full report in Codecov by Sentry. |
url <- ZIO.fromEither(URL.decode(s"http://localhost:$port")) | ||
id <- DynamicServer.deploy(Handler.ok.toHttpApp) | ||
proxy = Proxy.empty.url(url).headers(Headers(DynamicServer.APP_ID, id)) | ||
zclient <- ZIO.serviceWith[Client](_.copy(proxy = Some(proxy))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use our new proxy
method instead of copy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamgfraser I updated the code. Could you please check again!!!
0178a26
to
8bdffe6
Compare
@@ -68,6 +87,7 @@ object ClientProxySpec extends HttpRunnableSpec { | |||
ZLayer.succeed(NettyConfig.default), | |||
Scope.default, | |||
) | |||
_ = println(out) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stray debug statement.
@@ -109,6 +129,6 @@ object ClientProxySpec extends HttpRunnableSpec { | |||
|
|||
override def spec: Spec[TestEnvironment with Scope, Any] = suite("ClientProxy") { | |||
serve.as(List(clientProxySpec)) | |||
}.provideShared(DynamicServer.live, severTestLayer) @@ | |||
}.provideShared(DynamicServer.live, ZClient.default, severTestLayer) @@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to provide resources to just your test instead of to all tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to provide only to my test. But I getting below error -
zio.http.ZClient[Any,zio.http.Body,Throwable,zio.http.Response]
[error] /home/raj/Coding/scala/zio-http/zio-http/src/test/scala/zio/http/ClientProxySpec.scala:132:18:
[error]
[error] ──── ZLAYER ERROR ────────────────────────────────────────────────────
[error]
[error] Please provide a layer for the following type:
[error]
[error] 1. zio.http.ZClient[Any,zio.http.Body,Throwable,zio.http.Response]
[error]
[error] ──────────────────────────────────────────────────────────────────────
[error]
[error] }.provideShared(DynamicServer.live, severTestLayer) @@
[error] ^
+ Live
[error] one error found
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to provide the layer to your specific test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@adamgfraser I updated the test as below. After that I'm always getting timeout error
test("ZClient proxy respond Ok") {
val res =
for {
port <- ZIO.environmentWithZIO[DynamicServer](_.get.port)
url <- ZIO.fromEither(URL.decode(s"http://localhost:$port"))
id <- DynamicServer.deploy(Handler.ok.toHttpApp)
proxy = Proxy.empty.url(url).headers(Headers(DynamicServer.APP_ID, id))
zclient <- ZIO.serviceWith[Client](_.proxy(proxy))
out <- zclient
.request(
Request.get(url = url),
)
.provide(
Scope.default,
)
} yield out
assertZIO(res.either)(isRight)
}.provide(
DynamicServer.live,
ZClient.default,
) @@ timeout(60 seconds) @@ sequential @@ withLiveClock,
The error I'm getting is -
- ClientProxy - ClientProxySpec - ZClient proxy respond Ok
Timeout of 5 s exceeded.
When I used globally I couldn't encountered it.
Any idea?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test("ZClient proxy respond Ok") {
val res =
for {
port <- ZIO.environmentWithZIO[DynamicServer](_.get.port)
url <- ZIO.fromEither(URL.decode(s"http://localhost:$port"))
id <- DynamicServer.deploy(Handler.ok.toHttpApp)
proxy = Proxy.empty.url(url).headers(Headers(DynamicServer.APP_ID, id))
client <- ZIO.serviceWith[Client](_.proxy(proxy))
out <- client.request(Request.get(url = url))
} yield out
assertZIO(res.either)(isRight)
}.provideSome[DynamicServer](
Client.default,
Scope.default,
),
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adamgfraser That resolved my unit tests issues :)
447a87e
to
a20619d
Compare
@rajcspsg Can you resolve conflicts? @adamgfraser Is this good to merge? |
@jdegoes Yes! |
Thanks @jdegoes @adamgfraser I resolved the conflict. Could you please check again? |
/claim #2212
closes #2212