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

Add actor testcontainer tests #1192

Merged
merged 26 commits into from
Mar 1, 2025
Merged

Conversation

akkie
Copy link
Contributor

@akkie akkie commented Jan 16, 2025

Description

This PR adds testcontainer based integration tests for actors. This is to make sure that actors really work with testcontainers.

Issue reference

This PR was crated based on a Discord discussion with @salaboy to check if actors works with testcontainers.

@akkie akkie requested review from a team as code owners January 16, 2025 07:03
@akkie
Copy link
Contributor Author

akkie commented Jan 16, 2025

@salaboy I have currently the problem that the test fails with the following exception when trying to connect to the Dapr gRPC port.

Caused by: io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: /127.0.0.1:50001
Caused by: java.net.ConnectException: Connection refused
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:682)
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:1062)
        at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:336)
        at io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:339)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:776)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:724)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:650)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:562)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:994)
        at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1575)

Not sure why it uses port 50001, because this is the internal port. I think normally it should use the mapped port. Maybe you can have a look, if the test is not correct configured?

@salaboy
Copy link
Contributor

salaboy commented Jan 17, 2025

@akkie thanks a lot of this.. give me some time to look into this.. check the DCO, we need that to approve the PR. Click on the Details link to see the steps to fix it.

@akkie
Copy link
Contributor Author

akkie commented Jan 20, 2025

@salaboy Is it OK if I do a force push regarding the update of the DCO?

@salaboy
Copy link
Contributor

salaboy commented Jan 20, 2025

@akkie yeah.. that is your fork.. so it is ok

@akkie akkie force-pushed the actor-testcontainer branch from ee83cff to bec4bd2 Compare January 20, 2025 12:54
@salaboy
Copy link
Contributor

salaboy commented Jan 22, 2025

@akkie would you mind adding me as a collaborator to your fork? I am working on a fix, but I would love to push to your fork.. if not I can send you a patch to apply to your fork with the fix

@akkie
Copy link
Contributor Author

akkie commented Jan 22, 2025

@akkie would you mind adding me as a collaborator to your fork? I am working on a fix, but I would love to push to your fork.. if not I can send you a patch to apply to your fork with the fix

Done

@salaboy
Copy link
Contributor

salaboy commented Jan 22, 2025

@akkie I will push two commits to your fork, I am stuck with a new error now.. but at least the connection is working now.

@salaboy
Copy link
Contributor

salaboy commented Jan 22, 2025

Now I am stuck with this:

time="2025-01-22T17:41:56.55236659Z" level=debug msg="api error: code = Internal desc = error invoke actor method: did not find address for actor TestActor/f5893dd3-9d9c-4405-859e-b0c3b6aa2988" app_id=actor-dapr-app instance=780ae8017e66 scope=dapr.runtime.grpc.api type=log ver=1.14.1


io.dapr.exceptions.DaprException: INTERNAL: error invoke actor method: did not find address for actor TestActor/f5893dd3-9d9c-4405-859e-b0c3b6aa2988

But the connection is working as far as I can tell.

@salaboy
Copy link
Contributor

salaboy commented Jan 22, 2025

This is strange.. because it looks like we are hitting this: dapr/dapr#6783

https://github.com/dapr/java-sdk/blob/master/examples/src/main/java/io/dapr/examples/actors/DemoActorClient.java

@artursouza do you know if these examples are executed as part of the tests?

@akkie
Copy link
Contributor Author

akkie commented Jan 22, 2025

@salaboy This is exactly the message we get with our testcontainer setup:

fails to send binding event to http app channel, status code: 500 body: Dapr.DaprApiException: error invoke actor method: did not find address for actor

We use .NET and not Java.

@salaboy
Copy link
Contributor

salaboy commented Jan 22, 2025 via email

@salaboy
Copy link
Contributor

salaboy commented Jan 23, 2025

@akkie I am curious.. are you testing with an in-memory statestore?

@akkie
Copy link
Contributor Author

akkie commented Jan 23, 2025

@salaboy Yes, we are using Redis.

@salaboy
Copy link
Contributor

salaboy commented Jan 23, 2025

@akkie if you pull the code that I push can you check that you are getting the same results?

@akkie
Copy link
Contributor Author

akkie commented Jan 23, 2025

@salaboy You mean running the tests? If I run them, yes, I get the same result:

time="2025-01-23T15:27:19.585808881Z" level=debug msg="api error: code = Internal desc = error invoke actor method: did not find address for actor TestActor/7b7f7132-b3ab-4789-97d6-7dd9cfe6401d" app_id=actor-dapr-app instance=987309611b00 scope=dapr.runtime.grpc.api type=log ver=1.14.1

@salaboy
Copy link
Contributor

salaboy commented Jan 23, 2025

@akkie good news.. i think that I found the issue..
From what I can see there are two different things:

  1. We need to configure the app-port so the sidecar can contact back the application when it needs to execute an actor
  2. The actor runtime where we need to register actors (ActorRuntime.getInstance().registerActor(TestActorImpl.class);) is the one that is failing to get the right port. Because it is creating a new grpc channel without the overrides needed to connect to testcontainers..

I will try to fix this and push again.

@akkie
Copy link
Contributor Author

akkie commented Jan 30, 2025

@salaboy Any news regarding the issue?

@salaboy
Copy link
Contributor

salaboy commented Jan 30, 2025 via email

@salaboy
Copy link
Contributor

salaboy commented Jan 30, 2025 via email

@artur-ciocanu
Copy link
Contributor

@salaboy and @akkie I have found what's the culprit. Please check #1202. The TL;DR is that ActorRuntime doesn't allow properties override and that is why we see default GRPC port in logs and issues like actors not being found.

I will try to have a quick fix just to unblock this PR, but in general I think ActorRuntime should be aligned with WorkflowRuntime design for consistency sake.

CC: @artursouza @cicoyle

artur-ciocanu
artur-ciocanu previously approved these changes Feb 3, 2025
Copy link
Contributor

@artur-ciocanu artur-ciocanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akkie and @salaboy overall looks great, but there are some weird formatting issues that would be nice to address.

I think checkstyle will complain about it.

@akkie
Copy link
Contributor Author

akkie commented Feb 5, 2025

@artur-ciocanu Thanks for working on that. I fixed the formatting issues. Is there anything I need to do to get the tests running locally? They still failing for me with the message: api error: code = Internal desc = error invoke actor method: did not find address for actor TestActor/789215ad-9328-4019-8c86-6a4b6cc664a7

@salaboy
Copy link
Contributor

salaboy commented Feb 5, 2025

@akkie I think we are hitting the same issue as we hit with PubSub.. we need to investigate this further.. My expectation is that if we run this application in a Kubernetes Cluster, everything works.. so the issue is related with the sequence in which both the app and the sidecar gets bootstrapped by testcontainers.
I've created these examples for other features: #1208; we should add an actor Example there and run the applications locally to see if the issue exists outside of the test containers setup.

akkie and others added 11 commits February 23, 2025 12:05
Signed-off-by: Christian Kaps <[email protected]>
Co-authored-by: Cassie Coyle <[email protected]>
Signed-off-by: Christian Kaps <[email protected]>
…rs module (dapr#1210)

* feat: Adding basic HTTPEndpoint configuration support in testcontainers module

Signed-off-by: Laurent Broudoux <[email protected]>

* feat: dapr#1209 Adding test for HTTPEndpoint in testcontainers module

Signed-off-by: Laurent Broudoux <[email protected]>

---------

Signed-off-by: Laurent Broudoux <[email protected]>
Signed-off-by: Christian Kaps <[email protected]>
* Add app health check support to Dapr Testcontainer

Signed-off-by: Artur Ciocanu <[email protected]>

* Some minor cleanup

Signed-off-by: Artur Ciocanu <[email protected]>

* Move waiting to beforeEach, it looks more natural

Signed-off-by: Artur Ciocanu <[email protected]>

---------

Signed-off-by: Artur Ciocanu <[email protected]>
Co-authored-by: Artur Ciocanu <[email protected]>
Signed-off-by: Christian Kaps <[email protected]>
* Add app health check support to Dapr Testcontainer

Signed-off-by: Artur Ciocanu <[email protected]>

* Some minor cleanup

Signed-off-by: Artur Ciocanu <[email protected]>

* Move waiting to beforeEach, it looks more natural

Signed-off-by: Artur Ciocanu <[email protected]>

---------

Signed-off-by: Artur Ciocanu <[email protected]>
Co-authored-by: Artur Ciocanu <[email protected]>
Signed-off-by: Christian Kaps <[email protected]>
* Add app health check support to Dapr Testcontainer

Signed-off-by: Artur Ciocanu <[email protected]>

* Some minor cleanup

Signed-off-by: Artur Ciocanu <[email protected]>

* Move waiting to beforeEach, it looks more natural

Signed-off-by: Artur Ciocanu <[email protected]>

---------

Signed-off-by: Artur Ciocanu <[email protected]>
Co-authored-by: Artur Ciocanu <[email protected]>
Signed-off-by: Christian Kaps <[email protected]>
@akkie akkie force-pushed the actor-testcontainer branch from ace4137 to a9fdda8 Compare February 23, 2025 11:05
cicoyle
cicoyle previously approved these changes Feb 26, 2025
Copy link
Contributor

@cicoyle cicoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI is green and while the port overriding is not the prettiest, it works.

@jakesmolka
Copy link

@jakesmolka could you please the comments in this PR. As far as I remember you have mentioned that using Spring Boot Test with a defined port was problematic. I think we have found a way, it is not ideal, but it should work.

I wonder what are your thoughts.

Hey, thanks for letting me know @artur-ciocanu. I don’t have much time right now but gladly check it out later.

@artur-ciocanu
Copy link
Contributor

@artursouza could you please take a look and approve it. Thank you!

artursouza
artursouza previously approved these changes Feb 28, 2025
@artursouza artursouza dismissed stale reviews from cicoyle and themself via 3cc8e46 March 1, 2025 00:28
@artur-ciocanu
Copy link
Contributor

@artursouza and @cicoyle we need your review one more time. Thank you!

Copy link
Contributor

@artur-ciocanu artur-ciocanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Love it!

@dapr-bot dapr-bot merged commit efce229 into dapr:master Mar 1, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants