मैं एक सहायक है कि धागे का एक समूह समवर्ती कार्यों को निष्पादित करने शुरू कर सकते हैं बनाया है। सहायक सिंक्रनाइज़ेशन प्राइमेटिव और लॉगिंग तंत्र प्रदान करता है। इसका उपयोग किसी इकाई परीक्षण ढांचे के साथ संयोजन में किया जा सकता है।
[Test]
public void TwoCodeBlocksInParallelTest()
{
// This static method runs the provided Action delegates in parallel using threads
CTestHelper.Run(
c =>
{
Thread.Sleep(1000); // Here should be the code to provide something
CTestHelper.AddSequenceStep("Provide"); // We record a sequence step for the expectations after the test
CTestHelper.SetEvent();
},
c =>
{
CTestHelper.WaitEvent(); // We wait until we can consume what is provided
CTestHelper.AddSequenceStep("Consume"); // We record a sequence step for the expectations after the test
},
TimeSpan.FromSeconds(10)); // This is a timeout parameter, if the threads are deadlocked or take too long, the threads are terminated and a timeout exception is thrown
// After Run() completes we can analyze if the recorded sequence steps are in the correct order
Expect(CTestHelper.GetSequence(), Is.EqualTo(new[] { "Provide", "Consume" }));
}
यह घटकों में क्लाइंट/सर्वर या तुल्यकालन परीक्षण करने के लिए या बस एक समय समाप्ति के साथ एक धागा चलाने इस्तेमाल किया जा सकता: यहाँ एक इकाई परीक्षण से एक कोड टुकड़ा है। मैं अगले हफ्तों में इसे सुधारना जारी रखूंगा। यहां प्रोजेक्ट पेज है: Concurrency Testing Helper
स्रोत
2015-01-02 09:41:46
मुझे यकीन नहीं है कि कोई सटीक डुप्लीकेट हैं (हालांकि यह एक करीबी है: http: // stackoverflow।कॉम/प्रश्न/314580/कैसे-करें-मैं-प्रदर्शन-एक-इकाई-परीक्षण-उपयोग-धागे), लेकिन इस पर बहुत अच्छी सामग्री है। मैंने यहां मेरी प्रतिक्रिया में कुछ बेहतर चर्चाएं सूचीबद्ध की हैं: http://stackoverflow.com/questions/1520539/how-to-prove-that-multithreading-is-working/1520619#1520619। –
@ जेफ: आप इसे उत्तर के रूप में क्यों नहीं पोस्ट करते हैं - मेरे लिए काफी उपयोगी लगता है। – Dario