ISISComputingGroup / lewis-ess

Let's write intricate simulators!
GNU General Public License v3.0
21 stars 19 forks source link

Place adapter in separate thread #236

Closed MichaelWedel closed 7 years ago

MichaelWedel commented 7 years ago

This fixes #224.

This is a suggestion for how the threaded Adapters could work. As discussed on Slack, the old serial adapter processing has been replaced completely. AdapterCollection does not have a handle-Method any more, instead the Simulation simply sleeps for the appropriate time.

This still needs work on the Modbus adapter.

MikeHart85 commented 7 years ago

Made changes per my comments as discussed.

While testing, I noticed that our nosetests now take about 4-5 seconds instead of 0.1-0.2 seconds on my machine!!!

We should definitely figure out what's going on there before merging. Seems to hang one a few tests in particular.

MichaelWedel commented 7 years ago

Have we missed anything more? While fixing the tests I discovered that the connect-disconnect test for AdapterCollection failed sporadically. This blocks now until the adapter thread has completed the startup, so there's no synchronisation problem anymore.

MikeHart85 commented 7 years ago

Does mocking sleep really have any effect?

While we were trying to figure out why the tests were running so slow, I commented out the sleep in simulation at one point to see if it was the cause... and removing it had no effect. I assumed it must be already mocked or otherwise replaced/ignored during the tests.

MichaelWedel commented 7 years ago

Good question...I guess it's a kind of "insurance" to make sure sleep is never actually called even if we add tests later on. simulation.py is the only place I found where sleep is really used for something.

We could remove it if you want to, it's not really related.

MikeHart85 commented 7 years ago

Looks good, merging!