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

feat(nats): Add new module #439

Closed
wants to merge 18 commits into from
Closed

Conversation

bearrito
Copy link
Contributor

@bearrito bearrito commented Mar 2, 2024

Adds support for NATS. https://nats.io/

I wouldn't merge this yet. It's a bit awkward in determining if the container is ready (because of async) in the start method.
I'll sort out how I want to do that.

@bearrito bearrito changed the title Feature/nats feat(nats): Add new module Mar 2, 2024
@bearrito
Copy link
Contributor Author

bearrito commented Mar 5, 2024

@totallyzen Is this good to go?

@totallyzen
Copy link
Collaborator

Hey @bearrito can you give a bit more context on the use-case this covers?
There is a lot to unpack without some explanation in the README.rst

Cons:

  • adding a new class and a new dependency for 3 lines of code
  • the extra package causes poetry lock to become slower and slower

Alternatives:

  • we now support compose v2 and intend to release it with tc-python 4.0!
  • in compose you can define a healthcheck for your service and it trivialises a lot of use-cases to docker compose up --wait type operations

WDYT?

@bearrito
Copy link
Contributor Author

bearrito commented Mar 6, 2024

I'm not quite sure I understand the comments. This adds a new module for the Nats streaming pub/sub project.

Is the suggestion that instead of creating a new module for every container that we encapsulate that into docker compose files? I can see how that would simplify some things

If that's the case how do we add convenience methods for users without adding additional libraries to poetry?

@alexanderankin
Copy link
Member

i am also confused by the lot to unpack and the compose suggestion.

certainly you will be up and running faster with a compose file or adding this class to your project's test code than waiting for us because you can do that right away, but i dont think that means we are not adding any future modules

If that's the case how do we add convenience methods for users without adding additional libraries to poetry?

this is the real pickle - we basically want to avoid adding other libraries public apis to our public api

i would actually offer different feedback which is that we should probably use a log waiting strategy - testcontainers/testcontainers-java#1733

@bearrito
Copy link
Contributor Author

bearrito commented Mar 6, 2024

@alexanderankin Yeah, I can add the log waiting strategy in. No issue, if that's the only blocker I can do that immediately.
However, I don't want to add it if, the suggestion is : Do the this whole other thing with compose files.

@alexanderankin
Copy link
Member

alexanderankin commented Mar 6, 2024 via email

@bearrito
Copy link
Contributor Author

bearrito commented Mar 6, 2024

@alexanderankin Updated with logs waiting.

Side note it might be nice to expose the max wait time for the log wait. Right now it's set in the config file (which I could abuse). I think I'd generally want it less than 2 mins especially in CI where I could end up waiting NUM_TESTS * 2 mins. It does throw, but then it's considered a TRANSIENT and we have to wait. Either way..

@totallyzen
Copy link
Collaborator

totallyzen commented Mar 6, 2024 via email

@totallyzen
Copy link
Collaborator

Side note it might be nice to expose the max wait time for the log wait.

Fair point! This could be added to the ton of other safeguarding improvements, particularly #314 where we'd introduce a time-limit to container existence (thus ensuring that you don't leak test containers)

@bearrito
Copy link
Contributor Author

bearrito commented Mar 6, 2024

@totallyzen or @alexanderankin For this go around, since I've implemented the log based wait, is this good to go (after I fix the conflict)? Or do I need to go another direction?

@alexanderankin
Copy link
Member

alexanderankin commented Mar 6, 2024 via email

Copy link
Member

@alexanderankin alexanderankin left a comment

Choose a reason for hiding this comment

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

lgtm

bstrausser and others added 5 commits March 9, 2024 13:32
im not actually sure if this fixes it but does: make clickhouse waiting
look more like java-tc

many other discussions about removing dependency on sqlalchemy + drivers

---------

Co-authored-by: Bálint Bartha <[email protected]>
…ainers#380)

Fixes the following warning

```
sys:1: ResourceWarning: unclosed <socket.socket fd=7, family=AddressFamily.AF_UNIX, type=SocketKind.SOCK_STREAM, proto=0, raddr=/Users/rodrigo/.docker/run/docker.sock>
```
 Related to testcontainers#379

Co-authored-by: David Ankin <[email protected]>
oleg-nenashev and others added 4 commits March 9, 2024 13:32
The current one references 2017, and it is confusing since the website
may be perceived as outdated one

---------

Co-authored-by: Till Hoffmann <[email protected]>
Co-authored-by: David Ankin <[email protected]>
…ll before?) (testcontainers#461)

we were using this code to test if it was online or
not:`MongoClient(self.get_connection_url())`, but that doesn't actually
perform any connection, instead you have to do something like:

```python
    @wait_container_is_ready()
    def _connect(self):
        client = self.get_connection_client()
        # will raise pymongo.errors.ServerSelectionTimeoutError if no connection is established
        client.admin.command('ismaster')
```

thanks to @smparekh for pointing this out, in his PR:


https://github.com/testcontainers/testcontainers-python/pull/80/files#diff-cf09f76f44db0af04c58ddb456ccae39f7e29ce1d9208acd5f514c0a7dccb646R78

this PR implements the workaround described in the PR:

```python
@pytest.fixture(scope="session")
def test_client():
    # init mongo
    mongo_container = MongoDbContainer("mongo:4").start()
    wait_for_logs(mongo_container, 'waiting for connections on port 27017')
    ...

Co-authored-by: Shaishav Parekh <[email protected]>
@bearrito bearrito closed this Mar 9, 2024
@bearrito bearrito deleted the feature/nats branch March 9, 2024 18:41
@alexanderankin
Copy link
Member

there was no need to merge - there are no conflicts - see alexanderankin#6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants