Browse code

Slight TestBuildEnvUsage2 speedup

TestBuildEnvUsage2 was flagged in https://github.com/docker/docker/issues/19425
as one of the slowest integration tests. It's slow because it has some
comprehensive builder test cases that end up creating a lot of layers.
Even with a busybox base image, this can be expensive. It's not possible
to build "FROM scratch" because the test cases need the shell to ensure
environment variables are set correctly.

Some of the ENV and RUN statements can be combined. This causes fewer
layers to get created. Doing this produces a marginal improvement in the
runtime.

Before:

PASS: docker_cli_build_test.go:3956: DockerSuite.TestBuildEnvUsage2 43.619s

After:

PASS: docker_cli_build_test.go:3956: DockerSuite.TestBuildEnvUsage2 31.286s

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>

Aaron Lehmann authored on 2016/01/23 09:09:51
Showing 1 changed files
... ...
@@ -3959,24 +3959,14 @@ func (s *DockerSuite) TestBuildEnvUsage2(c *check.C) {
3959 3959
 	testRequires(c, DaemonIsLinux)
3960 3960
 	name := "testbuildenvusage2"
3961 3961
 	dockerfile := `FROM busybox
3962
-ENV    abc=def
3963
-RUN    [ "$abc" = "def" ]
3964
-ENV    def="hello world"
3965
-RUN    [ "$def" = "hello world" ]
3966
-ENV    def=hello\ world
3967
-RUN    [ "$def" = "hello world" ]
3968
-ENV    v1=abc v2="hi there"
3969
-RUN    [ "$v1" = "abc" ]
3970
-RUN    [ "$v2" = "hi there" ]
3971
-ENV    v3='boogie nights' v4="with'quotes too"
3972
-RUN    [ "$v3" = "boogie nights" ]
3973
-RUN    [ "$v4" = "with'quotes too" ]
3962
+ENV    abc=def def="hello world"
3963
+RUN    [ "$abc,$def" = "def,hello world" ]
3964
+ENV    def=hello\ world v1=abc v2="hi there" v3='boogie nights' v4="with'quotes too"
3965
+RUN    [ "$def,$v1,$v2,$v3,$v4" = "hello world,abc,hi there,boogie nights,with'quotes too" ]
3974 3966
 ENV    abc=zzz FROM=hello/docker/world
3975 3967
 ENV    abc=zzz TO=/docker/world/hello
3976 3968
 ADD    $FROM $TO
3977
-RUN    [ "$(cat $TO)" = "hello" ]
3978
-ENV    abc "zzz"
3979
-RUN    [ $abc = "zzz" ]
3969
+RUN    [ "$abc,$(cat $TO)" = "zzz,hello" ]
3980 3970
 ENV    abc 'yyy'
3981 3971
 RUN    [ $abc = 'yyy' ]
3982 3972
 ENV    abc=
... ...
@@ -3989,10 +3979,8 @@ RUN    [ "$abc" = "\$foo" ] && (echo "$abc" | grep foo)
3989 3989
 ENV    abc \$foo
3990 3990
 RUN    [ "$abc" = "\$foo" ] && (echo "$abc" | grep foo)
3991 3991
 
3992
-ENV    abc=\'foo\'
3993
-RUN    [ "$abc" = "'foo'" ]
3994
-ENV    abc=\"foo\"
3995
-RUN    [ "$abc" = "\"foo\"" ]
3992
+ENV    abc=\'foo\' abc2=\"foo\"
3993
+RUN    [ "$abc,$abc2" = "'foo',\"foo\"" ]
3996 3994
 ENV    abc "foo"
3997 3995
 RUN    [ "$abc" = "foo" ]
3998 3996
 ENV    abc 'foo'
... ...
@@ -4004,30 +3992,15 @@ RUN    [ "$abc" = '"foo"' ]
4004 4004
 
4005 4005
 ENV    abc=ABC
4006 4006
 RUN    [ "$abc" = "ABC" ]
4007
-ENV    def=${abc:-DEF}
4008
-RUN    [ "$def" = "ABC" ]
4009
-ENV    def=${ccc:-DEF}
4010
-RUN    [ "$def" = "DEF" ]
4011
-ENV    def=${ccc:-${def}xx}
4012
-RUN    [ "$def" = "DEFxx" ]
4013
-ENV    def=${def:+ALT}
4014
-RUN    [ "$def" = "ALT" ]
4015
-ENV    def=${def:+${abc}:}
4016
-RUN    [ "$def" = "ABC:" ]
4017
-ENV    def=${ccc:-\$abc:}
4018
-RUN    [ "$def" = '$abc:' ]
4019
-ENV    def=${ccc:-\${abc}:}
4020
-RUN    [ "$def" = '${abc:}' ]
4007
+ENV    def1=${abc:-DEF} def2=${ccc:-DEF}
4008
+ENV    def3=${ccc:-${def2}xx} def4=${abc:+ALT} def5=${def2:+${abc}:} def6=${ccc:-\$abc:} def7=${ccc:-\${abc}:}
4009
+RUN    [ "$def1,$def2,$def3,$def4,$def5,$def6,$def7" = 'ABC,DEF,DEFxx,ALT,ABC:,$abc:,${abc:}' ]
4021 4010
 ENV    mypath=${mypath:+$mypath:}/home
4022
-RUN    [ "$mypath" = '/home' ]
4023 4011
 ENV    mypath=${mypath:+$mypath:}/away
4024 4012
 RUN    [ "$mypath" = '/home:/away' ]
4025 4013
 
4026 4014
 ENV    e1=bar
4027
-ENV    e2=$e1
4028
-ENV    e3=$e11
4029
-ENV    e4=\$e1
4030
-ENV    e5=\$e11
4015
+ENV    e2=$e1 e3=$e11 e4=\$e1 e5=\$e11
4031 4016
 RUN    [ "$e0,$e1,$e2,$e3,$e4,$e5" = ',bar,bar,,$e1,$e11' ]
4032 4017
 
4033 4018
 ENV    ee1 bar
... ...
@@ -4037,8 +4010,7 @@ ENV    ee4 \$ee1
4037 4037
 ENV    ee5 \$ee11
4038 4038
 RUN    [ "$ee1,$ee2,$ee3,$ee4,$ee5" = 'bar,bar,,$ee1,$ee11' ]
4039 4039
 
4040
-ENV    eee1="foo"
4041
-ENV    eee2='foo'
4040
+ENV    eee1="foo" eee2='foo'
4042 4041
 ENV    eee3 "foo"
4043 4042
 ENV    eee4 'foo'
4044 4043
 RUN    [ "$eee1,$eee2,$eee3,$eee4" = 'foo,foo,foo,foo' ]