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 unit tests #10

Open
ahmetb opened this issue Dec 20, 2018 · 3 comments
Open

Add unit tests #10

ahmetb opened this issue Dec 20, 2018 · 3 comments
Labels
enhancement New feature or request long term issue

Comments

@ahmetb
Copy link
Collaborator

ahmetb commented Dec 20, 2018

It should be possible to easily spin-up grpc servers in-memory for tests and exercise probing capabilities.

It can be either execing out to a binary, or we could export the probing code to a pkg and just invoke that (but that wouldn't probably test the CLI flags).

@ahmetb ahmetb changed the title Add tests Add unit tests Dec 20, 2018
@ahmetb
Copy link
Collaborator Author

ahmetb commented Mar 5, 2019

I worked on this and the results are at testing branch. https://github.com/grpc-ecosystem/grpc-health-probe/tree/testing

This has reduced main.go (which, right now has all the code in the project) from 235 lines to 181 lines of code. However it resulted in the project come up to 613 lines of code.

Honestly I'm thinking since the project mostly relies on grpc-go’s behavior (e.g. returned error types/codes, timeouts etc), mocking all that stuff with testing seemed redundant. I'm initializing actual tcp server for connection testing, which is good, but then I have to replicate every kind of error (timeouts, general failures, tls hanging etc).

Similarly testing buildCredentials has been vastly unnecessary as we're trying to test the behavior of how gRPC credentials.TransportCredentials object behaves.

I call this a failed experiment and I think we should keep the source code of this project short, given it has not yielded any bug reports despite >80k downloads so far.

@arindamnayak
Copy link
Contributor

arindamnayak commented May 7, 2020

@ahmetb , once again I am trying to contribute to this issue as well. I have added one endtoend testcase - #43 . Most importantly, it does not require any change to existing source file which we intented to make it simple as per previous post.

It does following.

  • Created a grpc server which has the health check impl.
  • Made a binary of our source code and set it to the current path.
  • The new testcase will do following.
    • Lauch the grpc server
    • Execute the binary by pointing addr = addr of above grpc server
    • As an output, it expects it need to be in SERVING status.

@ahmetb
Copy link
Collaborator Author

ahmetb commented May 7, 2020

@arindamnayak You should definitely check out https://github.com/grpc-ecosystem/grpc-health-probe/tree/testing. I think where we actually need tests is around TLS/credentials/flags. It would be much better if we can bring the tests inside unit-test code instead of exec-ing (that way we can tweak the server etc).

@ahmetb ahmetb added enhancement New feature or request long term issue labels Jul 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request long term issue
Projects
None yet
Development

No branches or pull requests

2 participants