andri-ch / gotoword

vim plugin that gives users the possibility to write and access documentation about the word or expr. under cursor
GNU Lesser General Public License v3.0
0 stars 0 forks source link

put a "semaphore" between func tests and Vim to solve Vim delay #2

Closed andri-ch closed 9 years ago

andri-ch commented 9 years ago

related to 48 and 44, might fix them. When doing functional tests, and issuing a Helper* command there is a time delay between vim redrawing the screen with new information and the faster python tests that read the screen contents and extract info and make assumptions based on that info. So, in a test, I issue a command and read Vim's screen contents, but the contents might be the result of the previous test.

Sol:

  1. Put higher time.sleep() in the tests after the issued Helper* commands to allow Vim subprocess to react and hope that the timeout is enough.
  2. Only during functional tests, create in Vim a hidden buffer or other structure (or add an attribute to "app" object in gotoword plugin) to quickly store the currently executed test and at what stage in the test the plugin is. This way, tests can read it and can be sure to read from the screen the right contents at the right time, or add a timeout to allow Vim and its gotoword plugin to process cmds from tests. I've created a TestGotoword.delay(expected_result, timeout) which uses time.sleep() multiple times.
andri-ch commented 9 years ago
  1. Another solution would be to create a semaphore in the main thread of the gotoword. When the plugin does something like HelperSave -> issued by user or functional tests, it acquires the semaphore. When it exits HelperSave, it should release the semaphore.

In functional tests file, before issuing a cmd like HelperSave, tests should aquire the lock with: self.client.command('py semaphore.aquire') But that would only work if HelperSave is ran in a thread, right?

Vim delay could be solved with threads that run the Helper* cmds and a Lock/Semaphore object.

andri-ch commented 9 years ago

I've created a delay(timeout=1) function that sets a var inside editor. The function will be called after a time consuming command was sent to Vim. delay() will return when it manages to read the variable from editor (meaning that editor has completed the previous command) or it raises an exception after timeout seconds.