From djberg96 at gmail.com Wed Jan 19 21:29:49 2011 From: djberg96 at gmail.com (Daniel Berger) Date: Wed, 19 Jan 2011 19:29:49 -0700 Subject: [test-unit-users-en:00035] Instance variables freed? Message-ID: <4D379E1D.10505@gmail.com> Hi, I saw this: http://37signals.com/svn/posts/2742-the-road-to-faster-tests#extended Does test-unit 2 automatically free instance variables created in setup? If not, should it? Regards, Dan From kou at cozmixng.org Thu Jan 20 09:19:13 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Thu, 20 Jan 2011 23:19:13 +0900 (JST) Subject: [test-unit-users-en:00036] Re: Instance variables freed? In-Reply-To: <4D379E1D.10505@gmail.com> References: <4D379E1D.10505@gmail.com> Message-ID: <20110120.231913.627232544039153231.kou@cozmixng.org> Hi, In <4D379E1D.10505 at gmail.com> "[test-unit-users-en:00035] Instance variables freed?" on Wed, 19 Jan 2011 19:29:49 -0700, Daniel Berger wrote: > I saw this: > > http://37signals.com/svn/posts/2742-the-road-to-faster-tests#extended > > Does test-unit 2 automatically free instance variables > created in setup? If not, should it? What about this? class TestString < Test::Unit::TestCase class << self def startup @@variable1 = ... @@variable2 = ... @@variable3 = ... end end def setup ... end def test_xxx assert_zzz(..., @@variable1.yyy) end end Or we need to use @instance_variable instead of @@class_variable? Thanks, -- kou From dberger at globe.gov Thu Jan 20 10:22:19 2011 From: dberger at globe.gov (Daniel Berger) Date: Thu, 20 Jan 2011 08:22:19 -0700 Subject: [test-unit-users-en:00037] Re: Instance variables freed? In-Reply-To: <20110120.231913.627232544039153231.kou@cozmixng.org> Message-ID: On 1/20/11 7:19 AM, "Kouhei Sutou" wrote: > Hi, > > In <4D379E1D.10505 at gmail.com> > "[test-unit-users-en:00035] Instance variables freed?" on Wed, 19 Jan 2011 > 19:29:49 -0700, > Daniel Berger wrote: > >> I saw this: >> >> http://37signals.com/svn/posts/2742-the-road-to-faster-tests#extended >> >> Does test-unit 2 automatically free instance variables >> created in setup? If not, should it? > > What about this? > > class TestString < Test::Unit::TestCase > class << self > def startup > @@variable1 = ... > @@variable2 = ... > @@variable3 = ... > end > end > > def setup > ... > end > > def test_xxx > assert_zzz(..., @@variable1.yyy) > end > end > > Or we need to use @instance_variable instead of > @@class_variable? This diff is based on a comment from the article: --- lib/test/unit/testsuite.rb (revision 346) +++ lib/test/unit/testsuite.rb (working copy) - # Runs the tests and/or suites contained in this - # TestSuite. + # Runs the tests and/or suites contained in this TestSuite. def run(result, &progress_block) yield(STARTED, name) run_startup(result) - @tests.each do |test| + while test = @tests.shift test.run(result, &progress_block) end run_shutdown(result) @@ -59,7 +58,7 @@ @tests.each { |test| total_size += test.size } total_size end I'd have to run perftools to validate that it actually saves on memory, but all tests do pass with that change. I'm also not sure if this negatively impacts the "size" method. Regards, Dan From dberger at globe.gov Thu Jan 20 10:03:12 2011 From: dberger at globe.gov (Daniel Berger) Date: Thu, 20 Jan 2011 08:03:12 -0700 Subject: [test-unit-users-en:00038] Re: Instance variables freed? In-Reply-To: <20110120.231913.627232544039153231.kou@cozmixng.org> Message-ID: On 1/20/11 7:19 AM, "Kouhei Sutou" wrote: > Hi, > > In <4D379E1D.10505 at gmail.com> > "[test-unit-users-en:00035] Instance variables freed?" on Wed, 19 Jan 2011 > 19:29:49 -0700, > Daniel Berger wrote: > >> I saw this: >> >> http://37signals.com/svn/posts/2742-the-road-to-faster-tests#extended >> >> Does test-unit 2 automatically free instance variables >> created in setup? If not, should it? > > What about this? > > class TestString < Test::Unit::TestCase > class << self > def startup > @@variable1 = ... > @@variable2 = ... > @@variable3 = ... > end > end > > def setup > ... > end > > def test_xxx > assert_zzz(..., @@variable1.yyy) > end > end > > Or we need to use @instance_variable instead of > @@class_variable? I'm not sure what you mean. That would then require that we cleanup the class variables, wouldn't it? Anyway, that would require rewriting too many tests. Dan From kou at cozmixng.org Thu Jan 20 18:07:34 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Fri, 21 Jan 2011 08:07:34 +0900 (JST) Subject: [test-unit-users-en:00039] Re: Instance variables freed? In-Reply-To: References: <20110120.231913.627232544039153231.kou@cozmixng.org> Message-ID: <20110121.080734.283348358682359719.kou@cozmixng.org> Hi, In "[test-unit-users-en:00038] Re: Instance variables freed?" on Thu, 20 Jan 2011 08:03:12 -0700, Daniel Berger wrote: >> In <4D379E1D.10505 at gmail.com> >> "[test-unit-users-en:00035] Instance variables freed?" on Wed, 19 Jan 2011 >> 19:29:49 -0700, >> Daniel Berger wrote: >> >>> I saw this: >>> >>> http://37signals.com/svn/posts/2742-the-road-to-faster-tests#extended >>> >>> Does test-unit 2 automatically free instance variables >>> created in setup? If not, should it? >> >> What about this? > I'm not sure what you mean. That would then require that we cleanup the > class variables, wouldn't it? Anyway, that would require rewriting too many > tests. I'm so sorry... I misunderstood the original article... Thanks, -- kou From kou at cozmixng.org Thu Jan 20 18:09:39 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Fri, 21 Jan 2011 08:09:39 +0900 (JST) Subject: [test-unit-users-en:00040] Re: Instance variables freed? In-Reply-To: References: <20110120.231913.627232544039153231.kou@cozmixng.org> Message-ID: <20110121.080939.1866864107557511460.kou@cozmixng.org> Hi, In "[test-unit-users-en:00037] Re: Instance variables freed?" on Thu, 20 Jan 2011 08:22:19 -0700, Daniel Berger wrote: > This diff is based on a comment from the article: It seems good for me. > I'd have to run perftools to validate that it actually saves on memory, but > all tests do pass with that change. I'm also not sure if this negatively > impacts the "size" method. What aboud this? It doesn't break the "size" method after the "run" method. Index: testsuite.rb =================================================================== --- testsuite.rb (revision 346) +++ testsuite.rb (working copy) @@ -27,6 +27,7 @@ @name = name @tests = [] @test_case = test_case + @n_tests = 0 end # Runs the tests and/or suites contained in this @@ -34,7 +35,8 @@ def run(result, &progress_block) yield(STARTED, name) run_startup(result) - @tests.each do |test| + while test = @tests.shift + @n_tests += test.size test.run(result, &progress_block) end run_shutdown(result) @@ -55,7 +57,7 @@ # i.e. if the suite contains other suites, it counts the # tests within those suites, not the suites themselves. def size - total_size = 0 + total_size = @n_tests @tests.each { |test| total_size += test.size } total_size end Thanks, -- kou From djberg96 at gmail.com Thu Jan 20 20:33:57 2011 From: djberg96 at gmail.com (Daniel Berger) Date: Thu, 20 Jan 2011 18:33:57 -0700 Subject: [test-unit-users-en:00041] Re: Instance variables freed? In-Reply-To: <20110121.080939.1866864107557511460.kou@cozmixng.org> References: <20110120.231913.627232544039153231.kou@cozmixng.org> <20110121.080939.1866864107557511460.kou@cozmixng.org> Message-ID: <4D38E285.3080008@gmail.com> On 1/20/11 4:09 PM, Kouhei Sutou wrote: > Hi, > > In > "[test-unit-users-en:00037] Re: Instance variables freed?" on Thu, 20 Jan 2011 08:22:19 -0700, > Daniel Berger wrote: > >> This diff is based on a comment from the article: > > It seems good for me. > >> I'd have to run perftools to validate that it actually saves on memory, but >> all tests do pass with that change. I'm also not sure if this negatively >> impacts the "size" method. > > What aboud this? It doesn't break the "size" method after > the "run" method. > > Index: testsuite.rb > =================================================================== > --- testsuite.rb (revision 346) > +++ testsuite.rb (working copy) > @@ -27,6 +27,7 @@ > @name = name > @tests = [] > @test_case = test_case > + @n_tests = 0 > end > > # Runs the tests and/or suites contained in this > @@ -34,7 +35,8 @@ > def run(result,&progress_block) > yield(STARTED, name) > run_startup(result) > - @tests.each do |test| > + while test = @tests.shift > + @n_tests += test.size I'm not that familiar with the API. Should it be "+= test.size" or "+= 1"? Just checking. But, once that's determined, it looks good to me. Regards, Dan From kou at cozmixng.org Fri Jan 21 10:04:05 2011 From: kou at cozmixng.org (Kouhei Sutou) Date: Sat, 22 Jan 2011 00:04:05 +0900 (JST) Subject: [test-unit-users-en:00042] Re: Instance variables freed? In-Reply-To: <4D38E285.3080008@gmail.com> References: <20110121.080939.1866864107557511460.kou@cozmixng.org> <4D38E285.3080008@gmail.com> Message-ID: <20110122.000405.1707606133133793812.kou@cozmixng.org> Hi, In <4D38E285.3080008 at gmail.com> "[test-unit-users-en:00041] Re: Instance variables freed?" on Thu, 20 Jan 2011 18:33:57 -0700, Daniel Berger wrote: >> What aboud this? It doesn't break the "size" method after >> the "run" method. >> >> Index: testsuite.rb >> =================================================================== >> --- testsuite.rb (revision 346) >> +++ testsuite.rb (working copy) >> @@ -27,6 +27,7 @@ >> @name = name >> @tests = [] >> @test_case = test_case >> + @n_tests = 0 >> end >> >> # Runs the tests and/or suites contained in this >> @@ -34,7 +35,8 @@ >> def run(result,&progress_block) >> yield(STARTED, name) >> run_startup(result) >> - @tests.each do |test| >> + while test = @tests.shift >> + @n_tests += test.size > > I'm not that familiar with the API. Should it be "+= > test.size" or "+= 1"? Just checking. "+= test.size" is right because "test" may have sub-tests. > But, once that's determined, it looks good to me. Thanks for confirming. I've committed it into trunk. -- kou