sourcebots / robot-api

(Legacy) API to interface with robotd
http://docs.sourcebots.co.uk/api/
MIT License
4 stars 1 forks source link

Exploring an alternative communication architecture #57

Open PeterJCLaw opened 6 years ago

PeterJCLaw commented 6 years ago

Background

At the moment the robot-api tests depend on robotd, though don't really do much with the actual robotd boards. Instead they mainly use the BoardRunner as a mechanism to listen for the data sent over the socket (via injecting a message queue which it targets).

This approach appears simple on the surface however involves multiple processes and timeouts in the actual tests, meaning that there's a lot more complexity happening than appears at first.

While this approach also appears useful as integration level tests, as the underlying robotd Boards aren't used, there's nothing which actually validates that the data sent over the socket is going to work. Again the use of some of the robotd classes here creates the impression that more is being tested than is really the case.

Exploration

In #55 I've explored an alternative approach which avoids using the BoardRunner and instead mocks the socket on the robot-api side, connecting it directly to the real ServoAssembly device. We then mock out the serial connection from that robotd Board to the underlying arduino and primarily assert against the commands sent there.

This has its own downsides, notably that:

Suggestion

If we moved to a point where the majority of the transport layer (currently unix sockets) is swappable for an alternative backend, at least in code. If we don't actually implement a different backend for real use, I think that's fine; the aim here is to get better layering and thus testability.

Some of this is already present on the robotd side, with the extraction of the json wrapped socket that handles the data transport. I think robot-api would benefit from a similar approach.

Once we've extracted a mirror json wrapped socket which also handles reconnection (which I think is worth doing anyway), we can then override that connection much more easily in tests. A couple of ways that could be done are:

To support this for testing I suggest we would: