[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Simplify uptime processing in pinger; make it run witho...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv8972/lib/mixminion

Modified Files:
	Common.py test.py 
Log Message:
Simplify uptime processing in pinger; make it run without crashing.

Index: Common.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Common.py,v
retrieving revision 1.142
retrieving revision 1.143
diff -u -d -r1.142 -r1.143
--- Common.py	27 Jul 2004 21:51:18 -0000	1.142
+++ Common.py	2 Dec 2004 23:39:01 -0000	1.143
@@ -1327,7 +1327,7 @@
         r.edges = self.edges[:]
         return r
     def __iadd__(self, other):
-        """self += b : Causes this set to contain all points in itself but not
+        """self += b : Causes this set to contain all points in itself or
            in b."""
         self.edges += other.edges
         self._cleanEdges()
@@ -1398,6 +1398,15 @@
         r *= other
         return r
 
+    def getIntervalContaining(self, point):
+        """DOCDOC"""
+        #XXXX008 test
+        idx = bisect.bisect(self.edges, (point, '-'))
+        if idx < len(self.edges) and self.edges[idx][1] == '-':
+            return (self.edges[idx-1][0], self.edges[idx][0])
+        else:
+            return None, None
+
     def __contains__(self, other):
         """'a in self' is true when 'a' is a number contained in some interval
             in this set, or when 'a' is an IntervalSet that is a subset of
@@ -1427,6 +1436,14 @@
             s.append((self.edges[i][0], self.edges[i+1][0]))
         return s
 
+    def spanLength(self):
+        """DOCDOC"""
+        #XXXX008 testme
+        r = 0
+        for i in xrange(0, len(self.edges), 2):
+            r += self.edges[i+1][0] - self.edges[i][0]
+        return r
+
     def _checkRep(self):
         """Helper function: raises AssertionError if this set's data is
            corrupted."""

Index: test.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/test.py,v
retrieving revision 1.204
retrieving revision 1.205
diff -u -d -r1.204 -r1.205
--- test.py	2 Dec 2004 06:47:06 -0000	1.204
+++ test.py	2 Dec 2004 23:39:02 -0000	1.205
@@ -7727,6 +7727,7 @@
 #----------------------------------------------------------------------
 
 class PingerTests(TestCase):
+
     def testPinglogMemory(self):
         #XXXX We need way better tests here. 'now' needs to be an arg to
         #all the new log functions.
@@ -7734,6 +7735,13 @@
         if not P.canRunPinger():
             print "[Skipping ping tests; old python or missing pysqlite]",
 
+        l1 = [5, 9, 11, 13]
+        l2 = [6,10,10,12,15]
+        l3 = list(P._mergeIters(l1,l2))
+        l4 = l3[:]
+        l4.sort()
+        self.assertEquals(l3, l4)
+
         d = mix_mktemp()
         os.mkdir(d)
         loc = os.path.join(d, "db")
@@ -7749,9 +7757,9 @@
         log.gotPing("BZ"*10)
         log.gotPing("BN"*10)
         log.gotPing("BL"*10) #Never sent.
-        log.shutdown()
         log.rotate()
         log.calculateUptimes(time.time()-1000, time.time())
+        log.shutdown()
         #log.calculateDailyResults( ) #XXXX TEST
         log.close()
         log = P.openPingLog(loc)
@@ -7791,7 +7799,7 @@
     loader = unittest.TestLoader()
     tc = loader.loadTestsFromTestCase
 
-    if 0:
+    if 1:
         suite.addTest(tc(PingerTests))
         return suite
     testClasses = [MiscTests,