]>
Commit | Line | Data |
---|---|---|
74a2ea87 PD |
1 | #!/usr/bin/env python |
2 | ||
3 | import base64 | |
4 | import time | |
5 | import unittest | |
6 | from dnsdisttests import DNSDistTest | |
7 | ||
8 | class TestLuaThread(DNSDistTest): | |
9 | _consoleKey = DNSDistTest.generateConsoleKey() | |
10 | _consoleKeyB64 = base64.b64encode(_consoleKey).decode('ascii') | |
11 | ||
12 | _config_params = ['_consoleKeyB64', '_consolePort'] | |
13 | _config_template = """ | |
14 | setKey("%s") | |
15 | controlSocket("127.0.0.1:%s") | |
16 | ||
17 | counter = 0 | |
18 | function threadmessage(cmd, data) | |
19 | print("counter says", cmd, data.i) | |
20 | counter = tonumber(data.i) | |
21 | end | |
22 | ||
23 | newThread([==[ | |
24 | local socket = require'socket' | |
25 | local i=1 | |
26 | while true | |
27 | do | |
28 | socket.sleep(1) | |
29 | submitToMainThread("setCounter", {i=i}) | |
30 | i = i + 1 | |
31 | end | |
32 | ]==]) | |
33 | """ | |
34 | ||
35 | def testLuaThreadCounter(self): | |
36 | """ | |
37 | LuaThread: Test the lua newThread interface | |
38 | """ | |
39 | count1 = self.sendConsoleCommand('counter') | |
40 | time.sleep(3) | |
41 | count2 = self.sendConsoleCommand('counter') | |
42 | self.assertTrue(count2 > count1) |