Skip to content
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

Merged
merged 2 commits into from
Aug 30, 2023
Merged

Conversation

rajcspsg
Copy link
Contributor

@rajcspsg rajcspsg commented Jul 28, 2023

/claim #2212

closes #2212

@rajcspsg rajcspsg marked this pull request as ready for review July 28, 2023 17:57
)
.provide(
ZLayer.succeed(ZClient.Config.default),
proxied(proxy),
Copy link
Contributor Author

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 ClientDrivers.

Need your feedback on refactor/improve this unit test

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor Author

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?

@CLAassistant
Copy link

CLAassistant commented Aug 1, 2023

CLA assistant check
All committers have signed the CLA.

@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2023

Codecov Report

Patch coverage: 50.00% and project coverage change: +0.01% 🎉

Comparison is base (70eb173) 63.00% compared to head (8bdffe6) 63.01%.
Report is 5 commits behind head on main.

❗ 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     
Files Changed Coverage Δ
...o-http/src/main/scala/zio/http/ZClientAspect.scala 64.00% <ø> (ø)
zio-http/src/main/scala/zio/http/ZClient.scala 44.00% <50.00%> (+1.24%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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)))
Copy link
Contributor

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.

Copy link
Contributor Author

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!!!

@rajcspsg rajcspsg force-pushed the issue_2212 branch 3 times, most recently from 0178a26 to 8bdffe6 Compare August 12, 2023 06:15
@@ -68,6 +87,7 @@ object ClientProxySpec extends HttpRunnableSpec {
ZLayer.succeed(NettyConfig.default),
Scope.default,
)
_ = println(out)
Copy link
Contributor

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) @@
Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

@rajcspsg rajcspsg Aug 19, 2023

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?

Copy link
Contributor

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,
),

Copy link
Contributor Author

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 :)

@rajcspsg rajcspsg force-pushed the issue_2212 branch 3 times, most recently from 447a87e to a20619d Compare August 23, 2023 07:12
@jdegoes
Copy link
Member

jdegoes commented Aug 29, 2023

@rajcspsg Can you resolve conflicts?

@adamgfraser Is this good to merge?

@adamgfraser
Copy link
Contributor

@jdegoes Yes!

@rajcspsg
Copy link
Contributor Author

Thanks @jdegoes @adamgfraser I resolved the conflict. Could you please check again?

@adamgfraser adamgfraser merged commit 6411c97 into zio:main Aug 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Update client proxy settings
5 participants