The problem
I decided to do some testing. Each test was independent, and some were designed to throw errors. As these processes throw errors, why not put them in separate processes and trap the exit signals. Each test can be in its own directory with its own files this makes these tests independent of each other. Finally now that they are independent run them in parallel and collect the results.
Pretty simple, what could go wrong? Of course being computing nothing works as planned. The tests worked individually but running in parallel they failed. Tests were picking up files intended for the other test in the other directory. Current directory was shared state, and what the state of that location is is determined by the last process to change it. Relative file names were mapped against that global working directory.
The solution
The current directory was made part of process state, that is a change directory command that stored a value in the process dictionary. Local versions of file operations, file:consult, file:write_file and others were written to execute in a local context. Local io_format versions were written to output to the local directory to aid debugging. Problem solved.
Thinking generally
This problem is not that different from the global name problem I wrote on earlier. The context system should be extended with local directory and context sensitive file operations. It is understandable why the Erlang runtime system is built the way it is, but as this experience shows, we can do better.
No comments:
Post a Comment
Your comments are welcome.