chiark / gitweb /
Fix random_id(). Oops.
authorRichard Kettlewell <rjk@greenend.org.uk>
Sat, 24 May 2008 17:13:47 +0000 (18:13 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sat, 24 May 2008 17:13:47 +0000 (18:13 +0100)
Slightly more verbose tests.

lib/random.c
server/schedule.c
server/schedule.h
server/server.c
tests/schedule.py

index 21d0b09a93a63662dc5177b95f2fa7511544b13e..69e14095d81665562830276471330cb01be4bb56 100644 (file)
@@ -83,7 +83,7 @@ char *random_id(void) {
   char id[128];
 
   random_get(words, sizeof words);
-  basen(words, 4, id, sizeof id, 62);
+  basen(words, sizeof words / sizeof *words, id, sizeof id, 62);
   return xstrdup(id);
 }
 
index 7776c3c0486036fe1a912662a6a655bd632c3c54..c2cdb6d4ce352ebd403347cc18f82626db25662c 100644 (file)
@@ -249,8 +249,6 @@ void schedule_init(ev_source *ev) {
 /** @brief Create a scheduled event
  * @param ev Event loop
  * @param actiondata Action data
- *
- * The caller should set the timeout themselves.
  */
 static int schedule_add_tid(const char *id,
                            struct kvp *actiondata,
@@ -262,7 +260,8 @@ static int schedule_add_tid(const char *id,
   k.data = (void *)id;
   k.size = strlen(id);
   switch(err = trackdb_scheduledb->put(trackdb_scheduledb, tid, &k,
-                                       encode_data(&d, actiondata), 0)) {
+                                       encode_data(&d, actiondata),
+                                      DB_NOOVERWRITE)) {
   case 0:
     break;
   case DB_LOCK_DEADLOCK:
@@ -285,10 +284,10 @@ static int schedule_add_tid(const char *id,
  * is not allowed to perform them or if they are scheduled for a time
  * in the past.
  */
-char *schedule_add(ev_source *ev,
-                  struct kvp *actiondata) {
+const char *schedule_add(ev_source *ev,
+                        struct kvp *actiondata) {
   int e, n;
-  char *id;
+  const char *id;
   struct timeval when;
 
   /* TODO: handle recurring events */
@@ -314,7 +313,7 @@ char *schedule_add(ev_source *ev,
     id = random_id();
     WITH_TRANSACTION(schedule_add_tid(id, actiondata, tid));
   } while(e == DB_KEYEXIST);
-  ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, id);
+  ev_timeout(ev, 0/*handlep*/, &when, schedule_trigger, (void *)id);
   return id;
 }
 
index d68bafcc1a9a91bff102994937062722371b0875..0c7efa19a3df6e3bbeaa646a0147ebf470678c19 100644 (file)
@@ -22,8 +22,8 @@
 #define SCHEDULE_H
 
 void schedule_init(ev_source *ev);
-char *schedule_add(ev_source *ev,
-                  struct kvp *actiondata);
+const char *schedule_add(ev_source *ev,
+                        struct kvp *actiondata);
 int schedule_del(const char *id);
 struct kvp *schedule_get(const char *id);
 char **schedule_list(int *neventsp);
index e8e6a68668f1ede6b36df54c01b55a275093bdef..5df2d330a611c1b42e8f2c756177cad9fd10624a 100644 (file)
@@ -1567,7 +1567,7 @@ static int c_schedule_add(struct conn *c,
                          char **vec,
                          int nvec) {
   struct kvp *actiondata = 0;
-  char *id;
+  const char *id;
 
   /* Standard fields */
   kvp_set(&actiondata, "who", c->who);
index a3feaa87683fa06d9562bc79290e7496faeedf92..ac0b438708df899ce56d0fcbaaee3183eec45c2f 100755 (executable)
@@ -31,6 +31,7 @@ def test():
     print " waiting for nothing to be playing"
     while c.playing() is not None:
         time.sleep(1)
+        print "  ."
     now = int(time.time())
     track = "%s/Joe Bloggs/First Album/05:Fifth track.ogg" % dtest.tracks
     print " scheduling a track for the future"
@@ -45,6 +46,7 @@ def test():
     p = c.playing()
     while p is None and waited < 10:
         time.sleep(1)
+        print "  ."
         waited += 1
         p = c.playing()
     assert waited < 10, "checking track played within a reasonable period"
@@ -54,6 +56,7 @@ def test():
     print " waiting for nothing to be playing"
     while c.playing() is not None:
         time.sleep(1)
+        print "  ."
     print " scheduling an enable-random for the future"
     now = int(time.time())
     c.schedule_add(now + 4, "normal", "set-global", "random-play", "yes")
@@ -67,6 +70,7 @@ def test():
     p = c.playing()
     while p is None and waited < 10:
         time.sleep(1)
+        print "  ."
         waited += 1
         p = c.playing()
     assert waited < 10, "checking a track played within a reasonable period"
@@ -76,6 +80,7 @@ def test():
     print " waiting for nothing to be playing"
     while c.playing() is not None:
         time.sleep(1)
+        print "  ."
     print " scheduling track to play later via command line"
     now = int(time.time())
     dtest.command(["disorder",
@@ -96,6 +101,7 @@ def test():
     p = c.playing()
     while p is None and waited < 10:
         time.sleep(1)
+        print "  ."
         waited += 1
         p = c.playing()
     assert waited < 10, "checking track played within a reasonable period"
@@ -105,6 +111,7 @@ def test():
     print " waiting for nothing to be playing"
     while c.playing() is not None:
         time.sleep(1)
+        print "  ."
     print " scheduling an enable-random for later via command line"
     now = int(time.time())
     dtest.command(["disorder",
@@ -126,6 +133,7 @@ def test():
     p = c.playing()
     while p is None and waited < 10:
         time.sleep(1)
+        print "  ."
         waited += 1
         p = c.playing()
     assert waited < 10, "checking a track played within a reasonable period"
@@ -135,6 +143,7 @@ def test():
     print " waiting for nothing to be playing"
     while c.playing() is not None:
         time.sleep(1)
+        print "  ."
     print " scheduling a track for the future"
     now = int(time.time())
     c.schedule_add(now + 4, "normal", "play", track)
@@ -152,6 +161,7 @@ def test():
     p = c.playing()
     while p is None and waited < 10:
         time.sleep(1)
+        print "  ."
         waited += 1
         p = c.playing()
     assert p is None, "checking deleted scheduled event did not run"