27.07.2013 Views

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

2 Why We Need Model-Based Testing

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

264 Reactive Systems<br />

16.3 Asynchronous stepping<br />

Recall that testing requires a test harness called a stepper (Sections 8.3 and 12.2.3).<br />

In order to test a reactive IUT, the IUT has to support the asynchronous stepper<br />

interface IAsyncStepper that is declared in the N<strong>Model</strong>.Conformance namespace.<br />

The interface derives from the IStepper interface (see Section 12.2.3) and has<br />

one additional method called SetObserver. The SetObserver method is invoked<br />

initially by the conformance tester to set a callback function that enters observable<br />

actions into an observation queue. The observation queue is monitored by the conformance<br />

tester during test execution, as explained in Section 16.5.<br />

namespace N<strong>Model</strong>.Conformance<br />

{<br />

public delegate void ObserverDelegate(Action action);<br />

}<br />

public interface IAsyncStepper : IStepper<br />

{<br />

void SetObserver(ObserverDelegate observer);<br />

}<br />

When implementing an (asynchronous) stepper, the basic stepping functionality<br />

has not changed. The difference is that the stepper can now, in addition, implement a<br />

mechanism that directs asynchronous or spontaneous events produced by the IUT to<br />

the conformance tester. In other words, the job of the stepper is to map those events<br />

to observable actions that the model program understands and invoke the observer.<br />

By invoking the observer, the observable actions are entered into the observation<br />

queue to be processed by the conformance tester.<br />

Consider the SP protocol from Chapter 14. Figure 16.4 shows a mock implementation<br />

of an SP server. The server has a method Request that starts processing of<br />

requests, and an event ResponseEvent that is raised with feedback about finished<br />

requests to subscribers of the event. The server also has a Boolean property IsBusy<br />

that returns true if the server is not idle. To process a request, the server simply starts<br />

a worker thread that, after a short random delay, produces a response where the<br />

number of granted credits is a random number not more than the requested number<br />

of credits. This server is faulty, because it may grant no credits to the client even<br />

when the client has no pending requests and no more unused message ids.<br />

An asynchronous stepper for the server is shown in Figure 16.5. A call to<br />

SetObserver with an observer delegate subscribes a response handler (responder)<br />

to the response event of the server. The responder maps concrete responses from<br />

the server to observable actions and invokes the observer delegate that will enqueue<br />

more free ebooks download links at:<br />

http://www.ebook-x.com

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!