Anybody know much about DAPR? <https://pact-found...
# general
m
@Adam Schaff perhaps you could describe how DAPR works in a high level, to help us understand the question/problems?
b
Last time I read about it, the docs (frustratingly) didn't really explain what it is 😭
iirc, it's a framework that helps you write the moving parts of a distributed system, but abstracts away some of the infra & comms for consistency, almost becoming a bus
(from Wikipedia)
I don't know enough about implementing things with it to say how you'd add any kind of tests
☝️ 1
g
I know very little about Dapr but I believe Pact contracts exist in 2 forms: • a part specific to HTTP • a part for messages which is not specific to a techno (could be Kafka, PubSub, whatever I believe)
The 1st is HTTP specific, don't think this fits in Dapr world if Dapr abstract HTTP
The 2nd on the other hand is protocol agnostic and could fit in a Dapr world maybe?
But I don't know enough Dapr to say if it needs specific integration with Dapr or if the current implementation would be posisble to use directly in Dapr context
a
DAPR uses a sidecar pattern: https://docs.dapr.io/concepts/dapr-services/sidecar/ If we need to call another endpoint from our microservice, we just call dapr client methods, which take care of everything. It seems to me that the best way to do the contract testing would be to get the dapr sidecar talking to the pact mock server. But it's unclear how to make that happen, which is why I was hoping we weren't the first to try this and someone could give us some direction or even a sample to look at.
g
Depends what kind of contract verification you're setting up. I only do contract tests through unit tests without relying on anything started outside. (I'm used to JVM but I guess similar to .NET) (For HTTP contracts) Consumer side: unit test with pact stuff that starts a embedded server, I call my business code by pointing it to the mock server started by Pact. Here, if your code doesn't talk HTTP but only "Dapr-abstraction-over-HTTP", I don't see how you can make it work indeed. And I don't see how you would interact with a Dapr sidecar from your tests. Provider side: unit test that starts my app embedded web server and I point Pact code to my app embedded server so that it sends requests defined in the contracts and verify the response match the contract. Here I guess Dapr is not involved?
a
Thanks for your insight. Provider side: Yes, I believe I can test this without DAPR sidecar. Consumer side: Yes, the challenge would be getting the sidecar to talk to the mock server. I'm not sure if that is possible. I feel like maybe it is, but unfortunately I'm new to DAPR, so I'm not sure where to begin. Sounds like I really need to be posting this on a DAPR forum. I wish they used Slack! 😀 I suppose one other thought is that I could put my own interface around the DAPR method calls and have my tests implement it with an HTTP class, by-passing DAPR. The downside to this, of course, is that I'd be writing the very kind of code that DAPR promised me I wouldn't have to. Ah, the joys of being on the bleeding edge. I hope DAPR catches on more. I really do like what I've used of it so far. But there isn't a lot of info on testing best practices.
g
TBH I don't see that much value in over abstracting things (like Dapr does IMHO) but that's another discussion. Good to know people are using it and want to help it move in the right direction :)
a
Here is a follow-up. I posted on the Discord forum for DAPR. Folks there were super helpful, and I discovered that I was doing service invocation wrong (well, not the recommended way). There's a way to do it by getting an HttpClient from the dapr client. With that, I should be able to follow standard consumer side practices for contract testing. Woot! Of course, pub-sub will be a different (harder) challenge, but that can wait for the moment. I need to show some progress.
🙌 2
m
Oh, that’s great to know!
If you’re up for it, we’d love to see a recipe for DAPR here for future DAPRs 😛