default: diag

TEST = jobs
TODELETE = info $(TEST).export $(TEST).comm jobid actu del ftail

include ../Makefile.inc

$(TEST).comm:
	@echo 'DEBUT()'        > $(TEST).tmp
	@echo 'import time'   >> $(TEST).tmp
	@echo 'time.sleep(1)' >> $(TEST).tmp
	@echo 'FIN()'         >> $(TEST).tmp
	@mv -f $(TEST).tmp $@

info:
	$(as_run) --info > output.0.$@ 2> error.0.$@
	@if [ `grep -c 'SERV_VERS@' output.0.$@` -ne 2 ]; then \
		exit 14; \
	fi
	@grep EXIT_CODE output.0.$@ > $@

jobid: $(TEST).export $(TEST).comm
	$(as_run) --serv $< > output.1.$@ 2> error.1.$@
	@head -1 output.1.$@ | sed -e 's/^JOBID=//g' -e 's/ QUEUE.*//g' > jobid

actu: jobid
	sleep 0.2
	$(as_run) --actu `cat jobid` unittest_jobs interactif > output.2.$@ 2> error.2.$@
	@head -1 output.2.$@
	@if [ `head -1 output.2.$@ | grep -c 'ETAT=RUN DIAG=_ EXEC='` -ne 1 ]; then \
		echo 'ETAT != RUN'; \
		exit 24; \
	fi
	$(as_run) --tail `cat jobid` unittest_jobs interactif ftail 10 > output.3.$@ 2> error.3.$@
	@head -1 output.3.$@
	sleep 5
	$(as_run) --actu `cat jobid` unittest_jobs interactif > output.4.$@ 2> error.4.$@
	@head -1 output.4.$@
	@if [ `head -1 output.4.$@ | grep -c 'ETAT=ENDED DIAG=OK EXEC='` -ne 1 ]; then \
		echo 'ETAT != ENDED'; \
		exit 34; \
	fi
	@grep EXIT_CODE output.4.$@ > $@

del: actu
	$(as_run) --del `cat jobid` unittest_jobs interactif > output.5.$@ 2> error.5.$@
	@grep EXIT_CODE output.5.$@ > $@

unittest: info actu del
	@cp $< $@

jobclean = oui

