Skip to content

Commit

Permalink
Fix issue playframework#1463 by restoring behavior --timeout parameter
Browse files Browse the repository at this point in the history
The upgrade to python3 broke the processing of the --timeout parameter
due to a type mismatch (a string was compared to an integer).  The fix
is to always treat the --timeout parameter as a string, deferring to the
test runner to parse it and report errors.

This also fixes a typo in the name of a variable "webclient_timeout"
(it was named "weblcient_timeout").

It also adds some new regression tests for the auto-test functionality.
  • Loading branch information
David Costanzo committed Feb 9, 2024
1 parent f832ef8 commit b9181cd
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ samples-and-tests/i-am-a-developer/i-am-working-here
samples-and-tests/i-am-a-developer/i-am-creating-jobs-here
samples-and-tests/i-am-a-developer/i-am-testing-log-levels-here
samples-and-tests/i-am-a-developer/i-am-testing-ssl-config-here
samples-and-tests/i-am-a-developer/i-am-testing-auto-test-here
samples-and-tests/just-test-cases/attachments
samples-and-tests/booking/logs
samples-and-tests/booking/tmp
Expand Down
16 changes: 8 additions & 8 deletions framework/pym/play/commands/autotest.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,18 @@ def autotest(app, args):
add_options.append('-DrunSeleniumTests')

# Handle timeout parameter
weblcient_timeout = -1
webclient_timeout = None
if app.readConf('webclient.timeout'):
weblcient_timeout = app.readConf('webclient.timeout')
webclient_timeout = app.readConf('webclient.timeout')

for arg in args:
if arg.startswith('--timeout='):
args.remove(arg)
weblcient_timeout = arg[10:]
if weblcient_timeout >= 0:
add_options.append('-DwebclientTimeout=' + weblcient_timeout)
webclient_timeout = arg[10:]

if webclient_timeout is not None:
add_options.append('-DwebclientTimeout=' + webclient_timeout)

# Run app
test_result = os.path.join(app.path, 'test-result')
if os.path.exists(test_result):
Expand Down
68 changes: 68 additions & 0 deletions samples-and-tests/i-am-a-developer/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,74 @@
class IamADeveloper(unittest.TestCase):
play = None

def testAutoTest(self):
step('Hello, I am testing "play auto-test"')

self.working_directory = bootstrapWorkingDirectory('i-am-testing-auto-test-here')

# play new app
step('Create a new project')

app = '%s/testable-app' % self.working_directory

with callPlay(self, ['new', app, '--name=TESTABLEAPP']) as self.play:
self.assertTrue(waitFor(self.play, 'The new application will be created'))
self.assertTrue(waitFor(self.play, 'OK, the application is created'))
self.assertTrue(waitFor(self.play, 'Have fun!'))
self.play.wait()
self.assertEqual(self.play.returncode, 0)

# play auto-test
step('run with auto-test (the normal way)')

with callPlay(self, ['auto-test', app]) as self.play:
# wait for play to be ready
self.assertTrue(waitFor(self.play, 'BasicTest... PASSED '))
self.assertTrue(waitFor(self.play, 'ApplicationTest... PASSED '))
self.assertTrue(waitFor(self.play, 'Application... PASSED '))
self.assertTrue(waitFor(self.play, 'All tests passed'))
self.play.wait()
self.assertEqual(self.play.returncode, 0)

# play autotest is also accepted
step('run with autotest (also accepted)')

with callPlay(self, ['autotest', app]) as self.play:
# wait for play to be ready
self.assertTrue(waitFor(self.play, 'BasicTest... PASSED '))
self.assertTrue(waitFor(self.play, 'ApplicationTest... PASSED '))
self.assertTrue(waitFor(self.play, 'Application... PASSED '))
self.assertTrue(waitFor(self.play, 'All tests passed'))
self.play.wait()
self.assertEqual(self.play.returncode, 0)

# Run with a --timeout that is longer than the tests take
step('run with auto-test --timeout=60000')

with callPlay(self, ['auto-test', app, "--timeout=60000"]) as self.play:
# wait for play to be ready
self.assertTrue(waitFor(self.play, 'BasicTest... PASSED '))
self.assertTrue(waitFor(self.play, 'ApplicationTest... PASSED '))
self.assertTrue(waitFor(self.play, 'Application... PASSED '))
self.assertTrue(waitFor(self.play, 'All tests passed'))
self.play.wait()
self.assertEqual(self.play.returncode, 0)

# Run with a --timeout that is shorter than the tests take
step('run with auto-test --timeout=1')

with callPlay(self, ['auto-test', app, "--timeout=1"]) as self.play:
# wait for play to be ready
self.assertTrue(waitFor(self.play, 'BasicTest... ERROR '))
self.assertTrue(waitFor(self.play, 'ApplicationTest... ERROR '))
self.assertTrue(waitFor(self.play, 'Application... ERROR '))
self.assertTrue(waitFor(self.play, 'Tests did not successfully complete.'))
self.play.wait()
self.assertNotEqual(self.play.returncode, 0)

step("done testing auto-test")
self.play = None

def testSSLConfig(self):

# Testing ssl config
Expand Down

0 comments on commit b9181cd

Please sign in to comment.