############################################################################
# Purpose: Test of SLURM functionality
#          to be called from test21.30
#          Tests if the MaxWall limit is enforced
############################################################################
# Copyright (C) 2013 SchedMD LLC
# Written by Nathan Yee <nyee32@schedmd.com>
#
# This file is part of SLURM, a resource management program.
# For details, see <http://slurm.schedmd.com/>.
# Please also read the included file: DISCLAIMER.
#
# SLURM is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# SLURM is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along
# with SLURM; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA.
############################################################################

proc inc21_30_14 { } {
	global salloc srun acct bin_sleep number maxwall_num exit_code

	send_user "\nStarting MaxWall test\n"
	set job_id 0

	spawn $salloc --account=$acct -N1 -t$maxwall_num $srun $bin_sleep 10
	expect {
		-re "Granted job allocation ($number)" {
			set job_id $expect_out(1,string)
			send_user "\nJob $job_id has been submitted\n"
		}
		-re "Pending job allocation ($number)" {
			set job_id $expect_out(1,string)
			send_user "\nFAILURE: job $job_id should not be waiting for resources\n"
			set exit_code 1
		}
		timeout {
			send_user "\nFAILURE: salloc is not responding\n"
			set exit_code 1
		}
		eof {
			wait
		}
	}

	# Cancel job
        cancel_job $job_id

	spawn $salloc --account=$acct -N1 -t[expr $maxwall_num + 1] $srun $bin_sleep 10
	expect {
		-re "Pending job allocation ($number)" {
			set job_id $expect_out(1,string)
			send_user "\nJob $job_id is waiting for resources. This is expected\n"
		}
		-re "Granted job allocation ($number)" {
			set job_id $expect_out(1,string)
			send_user "\nFAILURE: job $job_id should be pending for resources, but is not\n"
			set exit_code 1
		}
		timeout {
			send_user "\nFAILURE: salloc is not responding\n"
			set exit_code 1
		}
		eof {
			wait
		}
	}

	# Cancel job
	cancel_job $job_id
}
