microsoft / codecoverage

MIT License
84 stars 11 forks source link

Enable Command Execution Across Containers/Network #103

Open hmiguel opened 9 months ago

hmiguel commented 9 months ago

Hi!

This is probably an enhancement request, but my current issue is:

Consider a CI/CD pipeline @integration-tests stage.

container-a: -./dotnet-coverage collect "Service.Api" --session-id integration-tests

container-b: -dotnet tests IntegrationTests ... (against container A) -dotnet-coverage shutdown integration-tests (unable to do it)

I want to be able to execute a gracefull shutdown (or snapshot) of container-a via container-b. How to do it?

A possible enhancement could involve setting something like --address container-a-hostname

Thanks in advance

jakubch1 commented 9 months ago

At the moment, our support is limited to operations on a single machine. At this time, we do not have plans to introduce this feature. We will keep issue open to see interest.

sahinM commented 5 months ago

@jakubch1 Is there an alternative approach how to retrieve the code coverage after I ran my test agast the running session integration-tests as @hmiguel mentioned? I thought is easily possible as described here, so I have the following:

Azure Pipeline:

  1. Starting an app in a K8s pod by an ENTRYPOINT: dotnet-coverage collect --session-id my-tests-session -f xml -o coverage.xml dotnet App.dll which runs fine.
  2. Running tests from the pipeline (obviously from the Azure pipeline build agent and NOT within the same pod) by: dotnet test --logger "trx;LogFileName=App.Tests.trx" App.Tests.dll
  3. Get the snapshot coverage after the tests are executed by: dotnet-coverage snapshot --output coverage-after-tests.xml my-tests-session
  4. Copy that file coverage-after-tests.xml via kubectl cp from the pod to the pipeline and see the results. => empty coverage xml file.
  5. I cannot do server shutdown and get the final coverage as well as @hmiguel stated, since the pod/container gets terminated, and I cannot just copy then the coverage file to the outside, and retrieve it from the build agent, I mean I could but it would be non-trivial thing. But in my case, the snapshot (which I thought is just the coverage of the app in time, after you performed something and the app is doing some stuff due to the test execution from step

Is that server shutdown needed? Should that snapshot not contain already the coverage I needed? I just need the code coverage of the server/App side. Again I followed this approach here, as you see. But I get an empty coverage result. What can be the reason for that? Because I did that in the pipeline, and this coverage-after-tests.xmlis just an empty coverage xml file.

Would be great if you could support here.

P.S. The test results (App.Tests.trx) looks good, and works, that I get successfully from the dotnet test command, but I guess this has nothing to do with the coverage and is a different thing.

jakubch1 commented 5 months ago

Your scenario looks good and should be supported. My guess is that k8s pod is missing some coverage dependencies or pdbs are not available. Could you please collect logs in step 1. ?

sahinM commented 5 months ago

Yes, here are the logs from step 1 in Verbose mode. logs-app.txt

How can I check, if pdbs are not available? I do not have any special configuration like in the docs here.

UPDATE (issue solved): Actually I fixed the issue by installing the missing dependency libxml2 on the Alpine Linux where the App is running. Thanks to your supported-os documentation 😊.

sahinM commented 5 months ago

Hi again, Now, after we refactored the Dockerfile to contain again a USER instruction for security reasons, to be non-root. The code-coverage snapshot returns with the error: "Invalid message tag." What does that mean? Does it miss some privileges? Thanks in advance.

fhnaseer commented 5 months ago

It seems like coverage file is corrupt. Can you please share what command lines you are executing? And the coverage file?

sahinM commented 5 months ago

Thanks for the response. We fixed it again, sorry. It turned out, that the file could not be written, due to permission issues on the Docker container.

carlos2martinize commented 1 month ago

What is private system firewall defender App's for