Harden Harness runtime, persistence and execution for Hand
This commit is contained in:
1 parent
09c30fe2d5
commit
0972eed3ea
164 files changed
+15912
-506
No files matched your search
@@ -0,0 +1,48 @@
|
||||
"""Reject skipped, failed, empty or unfinished Go qualification streams."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
def check(raw):
|
||||
active=set(); packages=set();passed_packages=set();tests=0;errors=[]
|
||||
for number,line in enumerate(raw.splitlines(),1):
|
||||
try:
|
||||
event=json.loads(line)
|
||||
if not isinstance(event,dict):raise ValueError('object required')
|
||||
except (ValueError,TypeError):
|
||||
errors.append(f'line {number}: invalid JSON event');continue
|
||||
action=event.get('Action');package=event.get('Package');test=event.get('Test')
|
||||
if action in ('output','build-output'):continue
|
||||
if action=='build-fail':errors.append('build failure');continue
|
||||
if not isinstance(package,str) or not package:
|
||||
errors.append(f'line {number}: package missing');continue
|
||||
if not test:
|
||||
if action=='start':
|
||||
if package in packages:errors.append('duplicate package start: '+package)
|
||||
packages.add(package)
|
||||
elif action=='pass':
|
||||
if package not in packages or package in passed_packages:errors.append('unmatched package pass: '+package)
|
||||
passed_packages.add(package)
|
||||
elif action in ('fail','skip'):errors.append(action+' package: '+package)
|
||||
else:errors.append('unknown package event: '+str(action))
|
||||
continue
|
||||
key=(package,test)
|
||||
if package not in packages or package in passed_packages:errors.append('test outside active package: '+str(key))
|
||||
if action=='run':
|
||||
if key in active:errors.append('duplicate running test: '+str(key))
|
||||
active.add(key)
|
||||
elif action in ('pass','fail','skip'):
|
||||
if key not in active:errors.append('unmatched test result: '+str(key))
|
||||
active.discard(key)
|
||||
if action!='pass':errors.append(action+' test: '+str(key))
|
||||
else:tests+=1
|
||||
elif action not in ('pause','cont'):errors.append('unknown test event: '+str(action))
|
||||
if not tests:errors.append('no passing test records')
|
||||
if not packages or packages!=passed_packages:errors.append('missing successful package completion')
|
||||
if active:errors.append('unfinished tests: '+str(sorted(active)))
|
||||
return dict(status='failed' if errors else 'passed',passed_test_records=tests,packages=len(packages),errors=errors)
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
result=check(Path(sys.argv[1]).read_text());print(json.dumps(result,indent=2));sys.exit(result['status']!='passed')
|
||||
@@ -0,0 +1,36 @@
|
||||
import json
|
||||
import unittest
|
||||
from check_test_events import check
|
||||
|
||||
|
||||
def stream(*events):
|
||||
return '\n'.join(json.dumps(dict(Package='p',**e)) for e in events)
|
||||
|
||||
|
||||
class EventGateTests(unittest.TestCase):
|
||||
def valid(self):
|
||||
return [dict(Action='start'),dict(Action='run',Test='TestOne'),dict(Action='pass',Test='TestOne'),dict(Action='pass')]
|
||||
|
||||
def test_complete_and_repeated_tests(self):
|
||||
e=self.valid();self.assertEqual(check(stream(*e))['status'],'passed')
|
||||
e[3:3]=e[1:3];self.assertEqual(check(stream(*e))['passed_test_records'],2)
|
||||
|
||||
def test_skipped_or_failed_is_never_green(self):
|
||||
for action in ('skip','fail'):
|
||||
e=self.valid();e[2]['Action']=action;self.assertEqual(check(stream(*e))['status'],'failed')
|
||||
|
||||
def test_missing_and_unmatched_events(self):
|
||||
e=self.valid()
|
||||
for i in range(len(e)):
|
||||
self.assertEqual(check(stream(*(e[:i]+e[i+1:])))['status'],'failed')
|
||||
|
||||
def test_empty_and_malformed(self):
|
||||
for raw in ('','not json','[]',stream(dict(Action='start'),dict(Action='pass'))):
|
||||
self.assertEqual(check(raw)['status'],'failed')
|
||||
|
||||
def test_hidden_build_failure(self):
|
||||
raw=stream(*self.valid())+'\n'+json.dumps(dict(Action='build-fail',ImportPath='other'))
|
||||
self.assertEqual(check(raw)['status'],'failed')
|
||||
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user