Click here to Skip to main content
15,888,579 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# web browser Pin
Jonteepersson967-May-15 2:13
Jonteepersson967-May-15 2:13 
GeneralRe: C# web browser Pin
Sascha Lefèvre7-May-15 2:20
professionalSascha Lefèvre7-May-15 2:20 
AnswerRe: C# web browser Pin
Ravi Bhavnani7-May-15 2:57
professionalRavi Bhavnani7-May-15 2:57 
QuestionHelp Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)7-May-15 0:25
Thomas Maierhofer (Tom)7-May-15 0:25 
AnswerRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen7-May-15 1:14
professionalEddy Vluggen7-May-15 1:14 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)7-May-15 1:52
Thomas Maierhofer (Tom)7-May-15 1:52 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen7-May-15 2:28
professionalEddy Vluggen7-May-15 2:28 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)7-May-15 3:03
Thomas Maierhofer (Tom)7-May-15 3:03 
The long method names are extracted by BDDfy to generate the test documentation:
http://docs.teststack.net/bddfy/

Behavior Driven Tests have all the same structure:
Given(...)
When( ... )
Then( ... )

Our old approach of concurrency testing does not fit in very well:

Test.Run(...)
Assert( Test.Is...)

You can't split this up semantically in Given/When/Then

The new approach is better:
Given ...
When ...
And I start write operation #1

is just a fluent Add() of this method:
.And(c => c.i_start_write_operation(1))
C#
void i_start_write_operation(int number)
{
    concurrencyTester.Start(
                     c =>
                     {
                         readerWriterLock.EnterWriteLock();
                         using (concurrencyTester.Marks["Write"].BeginSection())
                         {
                             concurrencyTester.Events[WriteOperationPending, number].Wait();
                         }
                         readerWriterLock.ExitWriteLock();
                     }, "Write Operation #{0}", number);
}

The execution of this test is controlled outside with the events:
C#
void release_write_operations(int[] numbers)
{

    foreach (var number in numbers)
    {
        concurrencyTester.Events[WriteOperationPending, number].Set();
    }

}

This is the point in the test where the operations are released:
C#
.When(c => c.release_read_operations(new[] { 1, 2 }))
.And(c => c.release_write_operations(new[] { 1, 2 }))

After that we can check what happens. The sections in the Marks collection are recorded and the relations Before, Intersect and After are queryable. So it is simple to express that the Read Sections should not intersect with the write sections.

This is the Timeline Dump of this test (EP means execution path):
Timeline Dump:
EP[0] Read-Enter
EP[2] Read-Enter
EP[2] Read-Leave
EP[0] Read-Leave
EP[1] Write-Enter
EP[1] Write-Leave
EP[3] Write-Enter
EP[3] Write-Leave

The first read on EP0 intersects with the second read on EP2, this is ok because multiple readers are allowed.

The first Write on EP1 is delayed until all reads are complete
The second Write on EP3 is delayed until the first read completes, this is OK, because only one writer is allowed.

Without the concurrency tester this is much harder to test.

GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen7-May-15 5:27
professionalEddy Vluggen7-May-15 5:27 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)7-May-15 9:11
Thomas Maierhofer (Tom)7-May-15 9:11 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen8-May-15 1:48
professionalEddy Vluggen8-May-15 1:48 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)8-May-15 11:09
Thomas Maierhofer (Tom)8-May-15 11:09 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen9-May-15 4:55
professionalEddy Vluggen9-May-15 4:55 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Thomas Maierhofer (Tom)9-May-15 6:29
Thomas Maierhofer (Tom)9-May-15 6:29 
GeneralRe: Help Needed: Unit Tests with multiple Threads / Concurrency / Correct Locking Pin
Eddy Vluggen9-May-15 12:17
professionalEddy Vluggen9-May-15 12:17 
QuestionExecute Multiple Commands using Process.StandardInput Pin
Django_Untaken6-May-15 23:56
Django_Untaken6-May-15 23:56 
AnswerRe: Execute Multiple Commands using Process.StandardInput Pin
Sascha Lefèvre7-May-15 0:40
professionalSascha Lefèvre7-May-15 0:40 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Django_Untaken7-May-15 0:47
Django_Untaken7-May-15 0:47 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Sascha Lefèvre7-May-15 1:00
professionalSascha Lefèvre7-May-15 1:00 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Eddy Vluggen7-May-15 1:16
professionalEddy Vluggen7-May-15 1:16 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Django_Untaken7-May-15 1:58
Django_Untaken7-May-15 1:58 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Eddy Vluggen7-May-15 2:18
professionalEddy Vluggen7-May-15 2:18 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Django_Untaken8-May-15 0:00
Django_Untaken8-May-15 0:00 
GeneralRe: Execute Multiple Commands using Process.StandardInput Pin
Eddy Vluggen8-May-15 1:40
professionalEddy Vluggen8-May-15 1:40 
QuestionHow know the state connected for udp client Pin
hasan hadi6-May-15 17:13
hasan hadi6-May-15 17:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.