On 6/25/07, <b class="gmail_sendername">Brendon Colby</b> <<a href="mailto:brendoncolby@gmail.com">brendoncolby@gmail.com</a>> wrote:<div><span class="gmail_quote"></span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
On 6/25/07, Christian Simms <<a href="mailto:christian.simms@gmail.com">christian.simms@gmail.com</a>> wrote:<br><br>[snip]<br>> I think you have a race condition because (I assume) self.p.lineReceived<br>> indirectly did a database insert, and then the
self.check did a database<br>> select. If that's true, you should make your test use Deferred's like this:<br><br>No - I'm just doing a series of runQuerys() when the server starts,<br>the callbacks of which populate dictionaries with objects. The test
<br>sends a string identifier to the server which checks whether or not it<br>exists in one of these dictionaries. When the test runs, the dict is<br>empty. However, the load method IS running, just (seemingly) after the<br>
test is run. I guess I'm not sure how to code a test for this, as in,<br>"after the database connection has been made and the data loaded, THEN<br>start running tests."<br></blockquote><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
[snip]<br></blockquote></div><br><br>Looks like I mis-assumed your problem, sorry. In the setUp method in your tests, you should return a Deferred which fires when all your data is loaded. This can be a pain if you already organized your code into classes inheriting from
twisted.application.service.Service which have startService/stopService calls. It's a pain because trial doesn't create an application object like running inside twistd does. So, in the case of writing unit tests for applications, you can abstract out your initialization code into a method, and then call that method directly in your setUp method.
<br><br>Cheers,<br>Christian<br>