|
Thomas Maierhofer (Tom) wrote: this.Given(c => c.new_reader_writer_lock())
.And(c => c.i_start_read_operation(1))
.And(c => c.i_wait_till_read_operation_is_pending(1))
.And(c => c.i_start_write_operation(1))
.And(c => c.i_start_read_operation(2))
.And(c => c.i_wait_till_read_operation_is_pending(2))
.And(c => c.i_start_write_operation(2))
.When(c => c.release_read_operations(new[] { 1, 2 }))
.And(c => c.release_write_operations(new[] { 1, 2 }))
.And(c => c.wait_for_test_end())
.Then(c => c.write_operations_should_not_intersect_with_read_operations())
.And(c => c.write_operations_should_not_intersect_with_other_write_operations())
.BDDfy();
What does the "fluent" part add? Looks like merely a wrapper around each statement, and not helping much in terms of readability. In fact, looks more like "everything" is wrapped in a local method with a very long name.
Thomas Maierhofer (Tom) wrote: So it should become very easy to write concurrency tests with this framework I'd love to see an in-depth article on the subject
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
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))
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:
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:
.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.
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: Behavior Driven Tests have all the same structure: Thanks for the link; I don't have any specific experience with BDT.
Thomas Maierhofer (Tom) wrote: Our old approach of concurrency testing does not fit in very well: I don't see the difference; either you .And(bla) or Assert(bla). As soon as it is repeated on each line, it becomes noise during reading.
Thomas Maierhofer (Tom) wrote: You can't split this up semantically in Given/When/Then Indeed, I usually start with mocking input and checking whether I get the expected output.
Thomas Maierhofer (Tom) wrote: Without the concurrency tester this is much harder to test. The only thing you wouldn't have is the path of the threads that are depending on another - that's the kind of dependency I try to avoid altogether.
Seriously, I would love an article; you sound like you know the subject very well, and I feel I must be blinded by my old habits (or defend them too much) to see the obvious advantages.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Quote: The only thing you wouldn't have is the path of the threads that are depending on another - that's the kind of dependency I try to avoid altogether.
If I want to test a synchronization primitive - here a Reader Writer lock, how can you avoid thread dependencies? It is all about the behavior on different threads, because that is what synchronization primitives do. Imagine a unit test (in pseudocode) that can perform the same test from scratch. How this may look like?
Quote: Thomas Maierhofer (Tom) wrote:
Our old approach of concurrency testing does not fit in very well: I don't see the difference; either you .And(bla) or Assert(bla). As soon as it is repeated on each line, it becomes noise during reading.
Maybe so you're just writing unit tests or maybe you are doing a little TDD. BDD is a slightly different approach. Love it or hate it.
In fact the ConcurrencyTester should work well in TDD and BDD scenarios.
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: If I want to test a synchronization primitive - here a Reader Writer lock, how
can you avoid thread dependencies? There's no silver bullet there, no single solution that will work in all cases. Instead of waiting for the reader-thread you might want to look at a queue.
Thomas Maierhofer (Tom) wrote: Imagine a unit test (in pseudocode) that can perform the same test from scratch. It would be testing whether the story as written works under the current conditions. How does it work if there's a deadlock because no reader-thread can be started (say, because someone is writing to the locked file)?
Thomas Maierhofer (Tom) wrote: BDD is a slightly different approach. Love it or hate it. I can't do either until I know it a bit better.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Quote:
Thomas Maierhofer (Tom) wrote:
If I want to test a synchronization primitive - here a Reader Writer lock, how
can you avoid thread dependencies?There's no silver bullet there, no single solution that will work in all cases. Instead of waiting for the reader-thread you might want to look at a queue.
Sorry you totally misunderstood me. If you are DEVELOPING a Reader Writer Lock Class, how could you possibly test YOR OWN Reader Writer Lock Class without threads? There is no queue, YOU are developing a Reader Writer Lock Class.
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: Sorry you totally misunderstood me. If you are DEVELOPING a Reader Writer Lock
Class I did not misunderstand; I would not have them in a single class.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
|
Thomas Maierhofer (Tom) wrote: Assuming I am the guy who developed this class, how would I test this class? Thouroughly, I hope.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hello guys. How do I send my slave application (in windows forms) multiple commands ? I am trying to show frame rate and video bitrate using two commands in mplayer (running as a slave app in windows form). Bit it shows only one things at a time, alternately. Here is what I am trying
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)");
objPlayerProcess.StandardInput.WriteLine(objPlayerProcess.StandardInput.NewLine);
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${video_bitrate}" + "(BitRate)");
How do I show both of them, at the same time ? Thanks for any input.
|
|
|
|
|
There's nothing wrong with the code you're showing here other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value. The actual problem is probably located in your receiving code or display code.
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
Sascha Lefévre wrote: .... other than I can't see how ${fps} and ${video_bitrate} should be replaced by some value.
Yes. Those will be handled by the player internally. Again, values are being shown but...one by one. Not at the same time.
|
|
|
|
|
With the second sentence of my previous reply I tried to hint at you that you need to provide more information / code
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
The slave application will be receiving them one by one. If you want to send them together, then make a single line of it, or change the slave to accept multiple arguments and wait with processing until there's a "I'm done sending stuff" command.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
I tried to send them in single line like this ...
objPlayerProcess.StandardInput.WriteLine("osd_show_property_text ${fps}" + "(FrameRate)" + objPlayerProcess.StandardInput.NewLine + "osd_show_property_text ${video_bitrate}" + "(BitRate)");
I don't know if there exists another method. This did not work either. It shows them alternately.
|
|
|
|
|
..because it is not a single line; there's a newline in there.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
nope. it did not work either. i am kinda stuck.
|
|
|
|
|
Post the code where your player is reading these values and we'll have a look
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Hi,
Iam Know how send and received but problem how know the state connected with IP , Port
this my code
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace etherent_send_and_recive_data
{
public partial class Form1 : Form
{
UdpClient udpClient;
private IPEndPoint ipend;
public Form1()
{
InitializeComponent();
udpClient = new UdpClient();
}
private void send_data_through_etherent( string send_data_ETH)
{
byte[] senddataETH = ASCIIEncoding.ASCII.GetBytes(send_data_ETH);
udpClient.Send(senddataETH,4);
}
private void button1_Click(object sender, EventArgs e)
{
int port;
byte res;
button1.Text = "disconnected";
port = int.Parse(textBox2.Text);
ipend = new IPEndPoint(IPAddress.Parse(textBox1.Text), port);
try
{
udpClient.Connect(ipend);
}
finally
{
button1.Text = "connected";
}
}
private void switch1_StateChanged(object sender, NationalInstruments.UI.ActionEventArgs e)
{
if(switch1.Value==true)send_data_through_etherent("S11E");
else send_data_through_etherent("S10E");
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
if(textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
if (textBox2.Text != string.Empty)
{
if (textBox1.TextLength >= 11) button1.Enabled = true;
}
}
}
}
the problem now in code button1_Click I need know the real state for connected for example if connected the button.text="connected" if closed or not connected button.text="disconnected"
how code for udp client about connected and closed
Regards
|
|
|
|
|
Ummm...UDP is connectionLESS so your question makes no sense.
|
|
|
|
|
Hi,
thank you for my support
Sir my equation how know the state for connection
i mean if press button will connected with ip for example 192.168.1.1 and port for example 10001 her equation how can know the connected with this ip and port is Successfully
now my project when press button is write connected but not iam sure the system is connected with this ip and port
I try to search about how know the state for connection with ip
some time is connected is ok but if closed socket must be program say for me now is disconnected
I hope now clear my equation
Best Regards
|
|
|
|
|
Your using UDP. Again, it's a CONNECTIONLESS protocol. THERE IS NO CONNECTION!
It's like tuning in a radio. The radio station doesn't have a connection to your radio and doesn't guarantee that you can receive the signal.
|
|
|
|
|
Thank Sir Now clear information about UDP
I try using TCP in the same project
Regards
|
|
|
|
|
TCP is like a phone call, UDP is like putting messages in a bottle and tossing them into the sea. If you need persistent connections and reliable communications you need to use TCP. If you do use UDP you have to appreciate that you just get data as it comes in, there is no connection or reliability in the data you receive. UDP is only suitable for a limited number of applications, or maybe if you're on a local LAN with an old-school token-ring network.
|
|
|
|
|
thank sir for this information and thank you for my support
now Iam understand about UDP
please Sir can be modification for my code by use TCP
or can be put small example about connected IP and Recived data and send data by used TCP
Best regards
|
|
|
|