Changeset 647ebce6 in trunk


Ignore:
Timestamp:
2014-08-17T14:51:19Z (11 years ago)
Author:
Daira Hopwood <daira@…>
Branches:
master
Children:
91077f0
Parents:
8f303df
git-author:
Daira Hopwood <daira@…> (2014-08-17 14:36:57)
git-committer:
Daira Hopwood <daira@…> (2014-08-17 14:51:19)
Message:

Better name for the file that causes a node to exit after a timeout when running unit tests. refs #1336

Signed-off-by: Daira Hopwood <daira@…>

Location:
src/allmydata
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified src/allmydata/client.py

    r8f303df r647ebce6  
    110110    STOREDIR = 'storage'
    111111    NODETYPE = "client"
    112     SUICIDE_PREVENTION_HOTLINE_FILE = "suicide_prevention_hotline"
     112    EXIT_TRIGGER_FILE = "exit_trigger"
    113113
    114114    # This means that if a storage server treats me as though I were a
     
    151151        self.init_drop_uploader()
    152152
    153         hotline_file = os.path.join(self.basedir,
    154                                     self.SUICIDE_PREVENTION_HOTLINE_FILE)
    155         if os.path.exists(hotline_file):
    156             age = time.time() - os.stat(hotline_file)[stat.ST_MTIME]
    157             self.log("hotline file noticed (%ds old), starting timer" % age)
    158             hotline = TimerService(1.0, self._check_hotline, hotline_file)
    159             hotline.setServiceParent(self)
     153        # If the node sees an exit_trigger file, it will poll every second to see
     154        # whether the file still exists, and what its mtime is. If the file does not
     155        # exist or has not been modified for a given timeout, the node will exit.
     156        exit_trigger_file = os.path.join(self.basedir,
     157                                         self.EXIT_TRIGGER_FILE)
     158        if os.path.exists(exit_trigger_file):
     159            age = time.time() - os.stat(exit_trigger_file)[stat.ST_MTIME]
     160            self.log("%s file noticed (%ds old), starting timer" % (self.EXIT_TRIGGER_FILE, age))
     161            exit_trigger = TimerService(1.0, self._check_exit_trigger, exit_trigger_file)
     162            exit_trigger.setServiceParent(self)
    160163
    161164        # this needs to happen last, so it can use getServiceNamed() to
     
    493496                self.log("couldn't start drop-uploader: %r", args=(e,))
    494497
    495     def _check_hotline(self, hotline_file):
    496         if os.path.exists(hotline_file):
    497             mtime = os.stat(hotline_file)[stat.ST_MTIME]
     498    def _check_exit_trigger(self, exit_trigger_file):
     499        if os.path.exists(exit_trigger_file):
     500            mtime = os.stat(exit_trigger_file)[stat.ST_MTIME]
    498501            if mtime > time.time() - 120.0:
    499502                return
    500503            else:
    501                 self.log("hotline file too old, shutting down")
     504                self.log("%s file too old, shutting down" % (self.EXIT_TRIGGER_FILE,))
    502505        else:
    503             self.log("hotline file missing, shutting down")
     506            self.log("%s file missing, shutting down" % (self.EXIT_TRIGGER_FILE,))
    504507        reactor.stop()
    505508
  • TabularUnified src/allmydata/test/check_memory.py

    r8f303df r647ebce6  
    146146    def tearDown(self, passthrough):
    147147        # the client node will shut down in a few seconds
    148         #os.remove(os.path.join(self.clientdir, "suicide_prevention_hotline"))
     148        #os.remove(os.path.join(self.clientdir, client.Client.EXIT_TRIGGER_FILE))
    149149        log.msg("shutting down SystemTest services")
    150150        if self.keepalive_file and os.path.exists(self.keepalive_file):
     
    256256        f.close()
    257257        self.keepalive_file = os.path.join(clientdir,
    258                                            "suicide_prevention_hotline")
     258                                           client.Client.EXIT_TRIGGER_FILE)
    259259        # now start updating the mtime.
    260260        self.touch_keepalive()
  • TabularUnified src/allmydata/test/test_client.py

    r8f303df r647ebce6  
    318318        dummy = "pb://wl74cyahejagspqgy4x5ukrvfnevlknt@127.0.0.1:58889/bogus"
    319319        fileutil.write(os.path.join(basedir, "tahoe.cfg"), BASECONFIG_I % dummy)
    320         fileutil.write(os.path.join(basedir, "suicide_prevention_hotline"), "")
     320        fileutil.write(os.path.join(basedir, client.Client.EXIT_TRIGGER_FILE), "")
    321321        client.Client(basedir)
    322322
     
    341341        def _restart(res):
    342342            # TODO: pause for slightly over one second, to let
    343             # Client._check_hotline poll the file once. That will exercise
     343            # Client._check_exit_trigger poll the file once. That will exercise
    344344            # another few lines. Then add another test in which we don't
    345             # update the file at all, and watch to see the node shutdown. (to
    346             # do this, use a modified node which overrides Node.shutdown(),
    347             # also change _check_hotline to use it instead of a raw
     345            # update the file at all, and watch to see the node shutdown.
     346            # (To do this, use a modified node which overrides Node.shutdown(),
     347            # also change _check_exit_trigger to use it instead of a raw
    348348            # reactor.stop, also instrument the shutdown event in an
    349             # attribute that we can check)
     349            # attribute that we can check.)
    350350            c2 = client.Client(basedir)
    351351            c2.setServiceParent(self.sparent)
  • TabularUnified src/allmydata/test/test_runner.py

    r8f303df r647ebce6  
     1import os.path, re, sys, subprocess
     2from cStringIO import StringIO
     3
    14from twisted.trial import unittest
    25
     
    47from twisted.internet import threads
    58
    6 import os.path, re, sys, subprocess
    7 from cStringIO import StringIO
    89from allmydata.util import fileutil, pollmixin
    910from allmydata.util.encodingutil import unicode_to_argv, unicode_to_output, get_filesystem_encoding
    1011from allmydata.scripts import runner
    11 
     12from allmydata.client import Client
    1213from allmydata.test import common_util
    1314import allmydata
     15
    1416
    1517timeout = 240
     
    358360        basedir = self.workdir("test_introducer")
    359361        c1 = os.path.join(basedir, "c1")
    360         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
     362        exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
    361363        TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
    362364        INTRODUCER_FURL_FILE = os.path.join(c1, "private", "introducer.furl")
     
    379381            # exit. This insures that even if the test fails (and the 'stop'
    380382            # command doesn't work), the client should still terminate.
    381             fileutil.write(HOTLINE_FILE, "")
     383            fileutil.write(exit_trigger_file, "")
    382384            # now it's safe to start the node
    383385        d.addCallback(_cb)
     
    390392            out, err, rc_or_sig = res
    391393
    392             fileutil.write(HOTLINE_FILE, "")
     394            fileutil.write(exit_trigger_file, "")
    393395            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    394396            self.failUnlessEqual(rc_or_sig, 0, errstr)
     
    417419            self.portnum = fileutil.read(PORTNUM_FILE)
    418420
    419             fileutil.write(HOTLINE_FILE, "")
     421            fileutil.write(exit_trigger_file, "")
    420422            self.failUnless(os.path.exists(TWISTD_PID_FILE))
    421423            self.failUnless(os.path.exists(NODE_URL_FILE))
     
    428430        def _then(res):
    429431            out, err, rc_or_sig = res
    430             fileutil.write(HOTLINE_FILE, "")
     432            fileutil.write(exit_trigger_file, "")
    431433            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    432434            self.failUnlessEqual(rc_or_sig, 0, errstr)
     
    452454        # 'tahoe stop' command takes a while.
    453455        def _stop(res):
    454             fileutil.write(HOTLINE_FILE, "")
     456            fileutil.write(exit_trigger_file, "")
    455457            self.failUnless(os.path.exists(TWISTD_PID_FILE))
    456458
     
    460462        def _after_stopping(res):
    461463            out, err, rc_or_sig = res
    462             fileutil.write(HOTLINE_FILE, "")
     464            fileutil.write(exit_trigger_file, "")
    463465            # the parent has exited by now
    464466            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
     
    471473            self.failIf(os.path.exists(TWISTD_PID_FILE))
    472474        d.addCallback(_after_stopping)
    473         d.addBoth(self._remove, HOTLINE_FILE)
     475        d.addBoth(self._remove, exit_trigger_file)
    474476        return d
    475477    # This test has hit a 240-second timeout on our feisty2.5 buildslave, and a 480-second timeout
     
    482484        basedir = self.workdir("test_client_no_noise")
    483485        c1 = os.path.join(basedir, "c1")
    484         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
     486        exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
    485487        TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
    486488        PORTNUM_FILE = os.path.join(c1, "client.port")
     
    496498            # that even if the 'stop' command doesn't work (and the test fails), the client should
    497499            # still terminate.
    498             fileutil.write(HOTLINE_FILE, "")
     500            fileutil.write(exit_trigger_file, "")
    499501            # now it's safe to start the node
    500502        d.addCallback(_cb)
     
    507509            out, err, rc_or_sig = res
    508510            errstr = "cc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    509             fileutil.write(HOTLINE_FILE, "")
     511            fileutil.write(exit_trigger_file, "")
    510512            self.failUnlessEqual(rc_or_sig, 0, errstr)
    511513            self.failUnlessEqual(out, "", errstr) # If you emit noise, you fail this test.
     
    537539            return self.run_bintahoe(["--quiet", "stop", c1])
    538540        d.addCallback(_stop)
    539         d.addBoth(self._remove, HOTLINE_FILE)
     541        d.addBoth(self._remove, exit_trigger_file)
    540542        return d
    541543
     
    544546        basedir = self.workdir("test_client")
    545547        c1 = os.path.join(basedir, "c1")
    546         HOTLINE_FILE = os.path.join(c1, "suicide_prevention_hotline")
     548        exit_trigger_file = os.path.join(c1, Client.EXIT_TRIGGER_FILE)
    547549        TWISTD_PID_FILE = os.path.join(c1, "twistd.pid")
    548550        PORTNUM_FILE = os.path.join(c1, "client.port")
     
    562564            # that even if the 'stop' command doesn't work (and the test fails), the client should
    563565            # still terminate.
    564             fileutil.write(HOTLINE_FILE, "")
     566            fileutil.write(exit_trigger_file, "")
    565567            # now it's safe to start the node
    566568        d.addCallback(_cb)
     
    572574        def _cb2(res):
    573575            out, err, rc_or_sig = res
    574             fileutil.write(HOTLINE_FILE, "")
     576            fileutil.write(exit_trigger_file, "")
    575577            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    576578            self.failUnlessEqual(rc_or_sig, 0, errstr)
     
    598600            self.portnum = fileutil.read(PORTNUM_FILE)
    599601
    600             fileutil.write(HOTLINE_FILE, "")
     602            fileutil.write(exit_trigger_file, "")
    601603            self.failUnless(os.path.exists(TWISTD_PID_FILE))
    602604
     
    609611            out, err, rc_or_sig = res
    610612
    611             fileutil.write(HOTLINE_FILE, "")
     613            fileutil.write(exit_trigger_file, "")
    612614            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
    613615            self.failUnlessEqual(rc_or_sig, 0, errstr)
     
    628630        # 'tahoe stop' command takes a while.
    629631        def _stop(res):
    630             fileutil.write(HOTLINE_FILE, "")
     632            fileutil.write(exit_trigger_file, "")
    631633            self.failUnless(os.path.exists(TWISTD_PID_FILE),
    632634                            (TWISTD_PID_FILE,
     
    638640            out, err, rc_or_sig = res
    639641
    640             fileutil.write(HOTLINE_FILE, "")
     642            fileutil.write(exit_trigger_file, "")
    641643            # the parent has exited by now
    642644            errstr = "rc=%d, OUT: '%s', ERR: '%s'" % (rc_or_sig, out, err)
     
    649651            self.failIf(os.path.exists(TWISTD_PID_FILE))
    650652        d.addCallback(_cb4)
    651         d.addBoth(self._remove, HOTLINE_FILE)
     653        d.addBoth(self._remove, exit_trigger_file)
    652654        return d
    653655
Note: See TracChangeset for help on using the changeset viewer.