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.

232 Compositional <strong>Model</strong>ing<br />

and it is not considered as part of the credits feature; that is, a Cancel request cannot<br />

be used by the client to get more credits. The model program of the cancellation<br />

feature is shown in Figure 14.7.<br />

State variables<br />

The cancellation model program has one state variable mode whose value is a map of<br />

pending request IDs that records for each entry whether it has been sent or cancelled<br />

by the client. Initially no request has been either sent or cancelled, so the value of<br />

mode is the empty map.<br />

Actions<br />

The action vocabulary of the cancellation model program contains all of the action<br />

symbols listed above. The credits field is ignored in all actions.<br />

The update rule of a Setup or a Work request updates the mode of that request ID<br />

to indicate that the request has been sent to the server. The enabling condition is that<br />

a request with the same ID is not pending.<br />

A Cancel request is enabled for all requests. This is needed to avoid race conditions<br />

between the client and the server. A Cancel request must have no effect on the<br />

behavior of the server unless the request being cancelled has actually been sent to<br />

the server and is not yet cancelled or completed.<br />

The update rule of a response action removes the pending request. A response<br />

action has a status field as the third argument. The value of the status field indicates<br />

whether the requested operation was cancelled or completed by the server. If the<br />

status of a response is Cancelled, it must be the case that cancellation of the<br />

corresponding request was sent by the client. Notice that the client may try to cancel<br />

a request but the cancellation arrives too late to the server who has already completed<br />

the request. Therefore, the status of a response to a request that has been cancelled<br />

by the client may be either Cancelled or Completed.<br />

Exploration<br />

Let us look at a particular scenario of the cancellation model program. First note<br />

that the model program behaves uniformly for all message IDs and there are no<br />

interactions or dependencies between actions with distinct message IDs. It is therefore<br />

enough to fix a single message ID, say 2. A convenient way to do so is to use<br />

the FSM scenario shown in Figure 14.8. Notice that the scenario disables all the<br />

work actions by including them in the vocabulary of the FSM. The composition<br />

of the scenario in Figure 14.8 with the cancellation model program is shown in<br />

Figure 14.9.<br />

For visual inspection and validation it is important to choose a small set of<br />

parameters. For example, if we add another message ID 3 into the scenario in<br />

Figure 14.8, that is, we consider the FSM in Figure 14.10 and compose it with<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!