Testing scenarios and approaches for unit testing user code
I was updating the documentation in the Unit Tests page and I realized that the new awesome TestCluster doesn't work automatically simply if you derive from it like it was the case for TestingSiloHost
In the case of TestingSiloHost , the default constructor for the class was creating 2 silos and also a default memory storage provider was being created as well.
Now the question is, should we add the configuration as a mandatory step for users which want to test their grain code? or we should modify the TestCluster ?
I'm ok with both, want to know what should I do to do it and send a PR.
Also TestingSiloHost had a static method to stop all silos which could be used in MS test cleanup like this
[ClassCleanup]
private static void CleanUp()
{
StopAllSilosIfRunning();
}
Should we add that to the TestCluster as well?
Hi @ashkan-saeedi-mazdeh
Thanks for updating our documentation, we really need that !!
Regards the question of new TestCluster, it is indeed slightly different from the old TestingSiloHost in aspect of their default constructor, but I want to clarify couple points.
- when default constructor
new TestCluster()is used, two silos are creating by default, with livenessServiceType asMembershipTableGrain. And it also init a client with default client config too. You can see a glimpse of part of the defaultTestClusterOptionsinTestClusterOPtions.FallbackOptionsclass, whereinitialSiloCountare set to 2. - And also TestCluster has a
StopAllSilos(), which I think it is equivalent toStopAllSilosIfRunning()but not a static method.
But you are right about that the default TestCluster doesn't have a storage provider configured. You need to configure it using
options.ClusterConfiguration.AddMemoryStorageProvider("Default");
options.ClusterConfiguration.AddMemoryStorageProvider("MemoryStore");'
But storage provider is not mandatory for every grain tests, only needed for cases like testing persistence. So I hold the opinion to not add this as a default config to default TestCluster. So default TestCluster is a working cluster with minimum resource configured (MVP!).