2011-03-16 13:18:12 +00:00
use strict ;
use Hydra::Schema ;
2012-03-13 12:18:40 +00:00
use Hydra::Model::DB ;
2011-03-16 13:18:12 +00:00
use Cwd ;
use Setup ;
2012-03-13 12:18:40 +00:00
my $ db = Hydra::Model::DB - > new ;
2011-03-16 13:18:12 +00:00
2016-04-12 20:27:11 +00:00
use Test::Simple tests = > 76 ;
2011-03-16 13:18:12 +00:00
hydra_setup ( $ db ) ;
my $ res ;
my $ stdout ;
my $ stderr ;
2011-03-17 08:48:27 +00:00
my $ jobsBaseUri = "file://" . getcwd ;
2011-03-16 13:18:12 +00:00
my $ project = $ db - > resultset ( 'Projects' ) - > create ( { name = > "tests" , displayname = > "" , owner = > "root" } ) ;
2011-03-17 11:55:39 +00:00
my $ jobset ;
2011-03-17 08:48:27 +00:00
2011-03-17 11:55:39 +00:00
# Most basic test case, no parameters
$ jobset = createBaseJobset ( "basic" , "basic.nix" ) ;
2011-03-17 08:48:27 +00:00
2011-03-17 11:55:39 +00:00
ok ( evalSucceeds ( $ jobset ) , "Evaluating jobs/basic.nix should exit with return code 0" ) ;
ok ( nrQueuedBuildsForJobset ( $ jobset ) == 3 , "Evaluating jobs/basic.nix should result in 3 builds" ) ;
2011-03-17 08:48:27 +00:00
2011-03-17 13:25:27 +00:00
for my $ build ( queuedBuildsForJobset ( $ jobset ) ) {
2013-01-23 12:48:02 +00:00
ok ( runBuild ( $ build ) , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should exit with code 0" ) ;
my $ newbuild = $ db - > resultset ( 'Builds' ) - > find ( $ build - > id ) ;
2015-06-25 13:29:22 +00:00
my $ expected = $ build - > job - > name eq "fails" ? 1 : $ build - > job - > name =~ /with_failed/ ? 6 : 0 ;
2013-01-23 12:48:02 +00:00
ok ( $ newbuild - > finished == 1 && $ newbuild - > buildstatus == $ expected , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should have buildstatus $expected" ) ;
2011-03-17 13:25:27 +00:00
}
2011-03-16 13:18:12 +00:00
2011-03-17 11:55:39 +00:00
# Test jobset with 2 jobs, one has parameter of succeeded build of the other
$ jobset = createJobsetWithOneInput ( "build-output-as-input" , "build-output-as-input.nix" , "build1" , "build" , "build1" ) ;
2011-03-16 13:18:12 +00:00
2011-03-17 11:55:39 +00:00
ok ( evalSucceeds ( $ jobset ) , "Evaluating jobs/build-output-as-input.nix should exit with return code 0" ) ;
ok ( nrQueuedBuildsForJobset ( $ jobset ) == 1 , "Evaluating jobs/build-output-as-input.nix for first time should result in 1 build in queue" ) ;
2011-03-24 13:45:01 +00:00
for my $ build ( queuedBuildsForJobset ( $ jobset ) ) {
2013-01-23 12:48:02 +00:00
ok ( runBuild ( $ build ) , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should exit with code 0" ) ;
my $ newbuild = $ db - > resultset ( 'Builds' ) - > find ( $ build - > id ) ;
ok ( $ newbuild - > finished == 1 && $ newbuild - > buildstatus == 0 , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should have buildstatus 0" ) ;
2011-03-24 13:45:01 +00:00
}
ok ( evalSucceeds ( $ jobset ) , "Evaluating jobs/build-output-as-input.nix for second time should exit with return code 0" ) ;
ok ( nrQueuedBuildsForJobset ( $ jobset ) == 1 , "Evaluating jobs/build-output-as-input.nix for second time after building build1 should result in 1 build in queue" ) ;
for my $ build ( queuedBuildsForJobset ( $ jobset ) ) {
2013-01-23 12:48:02 +00:00
ok ( runBuild ( $ build ) , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should exit with code 0" ) ;
my $ newbuild = $ db - > resultset ( 'Builds' ) - > find ( $ build - > id ) ;
ok ( $ newbuild - > finished == 1 && $ newbuild - > buildstatus == 0 , "Build '" . $ build - > job - > name . "' from jobs/basic.nix should have buildstatus 0" ) ;
2011-03-24 13:45:01 +00:00
}
2011-03-16 13:18:12 +00:00
2011-03-16 13:34:17 +00:00
2012-04-30 03:59:43 +00:00
# Test scm inputs
my @ scminputs = (
{
name = > "svn" ,
nixexpr = > "svn-input.nix" ,
type = > "svn" ,
uri = > "$jobsBaseUri/svn-repo" ,
update = > getcwd . "/jobs/svn-update.sh"
} ,
{
name = > "svn-checkout" ,
nixexpr = > "svn-checkout-input.nix" ,
type = > "svn-checkout" ,
uri = > "$jobsBaseUri/svn-checkout-repo" ,
update = > getcwd . "/jobs/svn-checkout-update.sh"
} ,
{
name = > "git" ,
nixexpr = > "git-input.nix" ,
type = > "git" ,
uri = > "$jobsBaseUri/git-repo" ,
update = > getcwd . "/jobs/git-update.sh"
} ,
2016-04-12 20:27:11 +00:00
{
name = > "git-rev" ,
nixexpr = > "git-rev-input.nix" ,
type = > "git" ,
uri = > "$jobsBaseUri/git-repo 7f60df502b96fd54bbfa64dd94b56d936a407701" ,
update = > getcwd . "/jobs/git-rev-update.sh"
} ,
2012-04-30 03:59:43 +00:00
{
name = > "deepgit" ,
nixexpr = > "deepgit-input.nix" ,
type = > "git" ,
uri = > "$jobsBaseUri/git-repo master 1" ,
update = > getcwd . "/jobs/git-update.sh"
} ,
{
name = > "bzr" ,
nixexpr = > "bzr-input.nix" ,
type = > "bzr" ,
uri = > "$jobsBaseUri/bzr-repo" ,
update = > getcwd . "/jobs/bzr-update.sh"
} ,
{
name = > "bzr-checkout" ,
nixexpr = > "bzr-checkout-input.nix" ,
type = > "bzr-checkout" ,
uri = > "$jobsBaseUri/bzr-checkout-repo" ,
update = > getcwd . "/jobs/bzr-checkout-update.sh"
} ,
{
name = > "hg" ,
nixexpr = > "hg-input.nix" ,
type = > "hg" ,
uri = > "$jobsBaseUri/hg-repo" ,
update = > getcwd . "/jobs/hg-update.sh"
2013-07-10 09:50:24 +00:00
} ,
{
name = > "darcs" ,
nixexpr = > "darcs-input.nix" ,
type = > "darcs" ,
uri = > "$jobsBaseUri/darcs-repo" ,
update = > getcwd . "/jobs/darcs-update.sh"
2012-04-30 03:59:43 +00:00
}
) ;
foreach my $ scm ( @ scminputs ) {
2013-01-23 12:48:02 +00:00
my $ scmName = $ scm - > { "name" } ;
my $ nixexpr = $ scm - > { "nixexpr" } ;
my $ type = $ scm - > { "type" } ;
my $ uri = $ scm - > { "uri" } ;
my $ update = $ scm - > { "update" } ;
$ jobset = createJobsetWithOneInput ( $ scmName , $ nixexpr , "src" , $ type , $ uri ) ;
my $ state = 0 ;
my $ q = 0 ;
my ( $ loop , $ updated ) = updateRepository ( $ scmName , $ update ) ;
while ( $ loop ) {
my $ c = 0 ;
# Verify that it can be fetched and possibly queued.
ok ( evalSucceeds ( $ jobset ) , "$scmName:$state.$c: Evaluating nix-expression." ) ; $ c + + ;
# Verify that the evaluation has queued a new job and evaluate again to ...
if ( $ updated ) {
$ q + + ;
ok ( nrQueuedBuildsForJobset ( $ jobset ) == $ q , "$scmName:$state.$c: Expect $q jobs in the queue." ) ; $ c + + ;
ok ( evalSucceeds ( $ jobset ) , "$scmName:$state.$c: Evaluating nix-expression again." ) ; $ c + + ;
}
# ... check that it is deterministic and not queued again.
2012-04-30 03:59:43 +00:00
ok ( nrQueuedBuildsForJobset ( $ jobset ) == $ q , "$scmName:$state.$c: Expect $q jobs in the queue." ) ; $ c + + ;
2013-01-23 12:48:02 +00:00
$ state + + ;
( $ loop , $ updated ) = updateRepository ( $ scmName , $ update , getcwd . "/$scmName-repo/" ) ;
}
2012-04-15 01:17:35 +00:00
}
2013-03-20 17:05:21 +00:00
# Test build products
$ jobset = createBaseJobset ( "build-products" , "build-products.nix" ) ;
ok ( evalSucceeds ( $ jobset ) , "Evaluating jobs/build-products.nix should exit with return code 0" ) ;
ok ( nrQueuedBuildsForJobset ( $ jobset ) == 2 , "Evaluating jobs/build-products.nix should result in 2 builds" ) ;
for my $ build ( queuedBuildsForJobset ( $ jobset ) ) {
ok ( runBuild ( $ build ) , "Build '" . $ build - > job - > name . "' from jobs/build-products.nix should exit with code 0" ) ;
my $ newbuild = $ db - > resultset ( 'Builds' ) - > find ( $ build - > id ) ;
ok ( $ newbuild - > finished == 1 && $ newbuild - > buildstatus == 0 , "Build '" . $ build - > job - > name . "' from jobs/build-products.nix should have buildstatus 0" ) ;
my $ buildproducts = $ db - > resultset ( 'BuildProducts' ) - > search ( { build = > $ build - > id } ) ;
my $ buildproduct = $ buildproducts - > next ;
if ( $ build - > job - > name eq "simple" ) {
ok ( $ buildproduct - > name eq "text.txt" , "We should have text.txt, but found: " . $ buildproduct - > name . "\n" ) ;
} elsif ( $ build - > job - > name eq "with_spaces" ) {
ok ( $ buildproduct - > name eq "some text.txt" , "We should have: \"some text.txt\", but found: " . $ buildproduct - > name . "\n" ) ;
}
}