[erlang-questions] Fault injection for testing?

Morten Krogh <>
Mon Dec 20 16:14:11 CET 2010


Hi

Why don't you test the various situations that could elicit an error?

The filename is a directory.
Out of space or quota is used.
No permissions.
The path doesn't exist.

Morten.



On 12/20/10 2:32 PM, Attila Rajmund Nohl wrote:
> Hello!
>
> Testing error handling is complicated, because it might be hard to
> cause the error situation in the first place, which in my case it's a
> file writing error:
>
>      case file:write_file(FileName,<<Index:8/integer>>) of
> 	ok ->  ok;
> 	Error ->
> 	io:format(standard_error, "~p ~p Error: '~p' ~n", [?MODULE, ?LINE, Error]),
> 	    exit(open_lastwritten_file)
>      end.
>
> I could modify my code to fail is some debug flag is turned on, but it
> has a (minor) performance impact. My other idea is to make sure that
> the write_file fails by injecting the fault into the OTP library, i.e.
> before the testcase runs in the automatic tests, load a faulty 'file'
> module where the write_file function fails (I happen to know the
> filename, so it won't fail for other uses), execute the testcase, then
> remove the faulty file module.
>
> Do you have any other ideas on how to test these kind of error
> handling code? Testing the function separately, outside the whole
> application doesn't do it, because it wouldn't detect possible
> deadlocks (the original version of this code actually had a deadlock).
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:
>



More information about the erlang-questions mailing list