chiark / gitweb /
More careful testing of scratching, and correctly handle the case
authorRichard Kettlewell <rjk@greenend.org.uk>
Thu, 10 Jan 2008 14:39:37 +0000 (14:39 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Thu, 10 Jan 2008 14:39:37 +0000 (14:39 +0000)
where a track is scratched before the speaker process has got to grips
with it.

lib/speaker-protocol.h
server/play.c
server/speaker.c
tests/play.py

index ac4fdf0efc5fbb57a7ecf176c89c964d79fbfe4a..520a0c6d4ba3369fad952acaa003a2ae7fbbda8a 100644 (file)
@@ -42,6 +42,7 @@ struct speaker_message {
    * - @ref SM_PAUSED
    * - @ref SM_FINISHED
    * - @ref SM_PLAYING
+   * - @ref SM_UNKNOWN
    */
   int type;
 
@@ -83,6 +84,9 @@ struct speaker_message {
 /** @brief Finished playing track @c id */
 #define SM_FINISHED 129
 
+/** @brief Never heard of track @c id */
+#define SM_UNKNOWN 130
+
 /** @brief Currently track @c id, @c data seconds in
  *
  * This is sent from time to time while a track is playing.
index fa46329fc63a5436073ff018e86b5a336a09b3d7..d73aec7482bac24cedd54268e96479d186dc14f8 100644 (file)
@@ -116,6 +116,11 @@ static int speaker_readable(ev_source *ev, int fd,
     D(("SM_FINISHED %s", sm.id));
     finished(ev);
     break;
+  case SM_UNKNOWN:
+    /* we asked for an unknown track to be cancelled */
+    if(playing && !strcmp(sm.id, playing->id))
+      finished(ev);
+    break;
   case SM_PLAYING:
     /* track ID is playing, DATA seconds played */
     D(("SM_PLAYING %s %ld", sm.id, sm.data));
index ae43f120fd6513e9af92b988c166f452b7b86a8e..407b1d7a6f37000e9d1334eadf8d5c0333dc881a 100644 (file)
@@ -563,8 +563,11 @@ static void mainloop(void) {
              playing = 0;
             }
            destroy(t);
-         } else
+         } else {
+            sm.type = SM_UNKNOWN;
+            speaker_send(1, &sm);
            error(0, "SM_CANCEL for unknown track %s", sm.id);
+          }
           report();
          break;
        case SM_RELOAD:
index c638572466943f31ae801d23857f320ee347af6d..ce5cbb1c6d05aac0fc4f0b5e73d83cb02f65d326 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 #
 # This file is part of DisOrder.
-# Copyright (C) 2007 Richard Kettlewell
+# Copyright (C) 2007, 2008 Richard Kettlewell
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -25,9 +25,12 @@ def test():
     dtest.start_daemon()
     dtest.create_user()
     c = disorder.client()
+    c.random_disable()
+    assert c.random_enabled() == False
     track = u"%s/Joe Bloggs/First Album/02:Second track.ogg" % dtest.tracks
     print " adding track to queue"
     c.disable()
+    assert c.enabled() == False
     c.play(track)
     print " checking track turned up in queue"
     q = c.queue()
@@ -38,6 +41,7 @@ def test():
     i = t['id']
     print " waiting for track"
     c.enable()
+    assert c.enabled() == True
     p = c.playing()
     r = c.recent()
     while not((p is not None and p['id'] == i)
@@ -54,33 +58,42 @@ def test():
     assert len(ts) == 1, "check track appears exactly once in recent"
     t = ts[0]
     assert t['submitter'] == u'fred', "check recent entry submitter"
-    print " disabling play"
-    c.disable()
-    print " scratching current track"
-    p = c.playing()
-    i = p['id']
-    c.scratch(i)
-    print " checking scratched track turned up in recent list"
-    while (p is not None and p['id'] == i):
-        time.sleep(1)
+
+    print " testing scratches"
+    retry = False
+    while True:
+        c.disable()
+        print " starting a track"
+        c.play(track)
+        c.enable()
         p = c.playing()
-    r = c.recent()
-    ts = filter(lambda t: t['id'] == i, r)
-    assert len(ts) == 1, "check scratched track appears exactly once in recent"
-    assert ts[0]['state'] == 'scratched', "checking track scratched"
+        if p is None:
+            print " track played too quickly, trying again..."
+            continue
+        print " scratching track"
+        i = p['id']
+        c.scratch(i)
+        print " waiting for track to finish"
+        p = c.playing()
+        while (p is not None and p['id'] == i):
+            time.sleep(1)
+            p = c.playing()
+        print " checking scratched track turned up in recent list"
+        r = c.recent()
+        ts = filter(lambda t: t['id'] == i, r)
+        assert len(ts) == 1, "check scratched track appears exactly once in recent"
+        if ts[0]['state'] == 'ok':
+            print " track played too quickly, trying again..."
+            continue
+        assert ts[0]['state'] == 'scratched', "checking track scratched"
+        break
     print " waiting for scratch to complete"
-    while (p is not None and p['state'] == 'isscratch'):
+    p = c.recent()
+    while p is not None:
         time.sleep(1)
         p = c.playing()
     assert p is None, "checking nothing is playing"
-    c.random_disable()
-    assert c.random_enabled() == False
-    assert c.enabled() == False
-    c.enable()
     assert c.enabled() == True
-    time.sleep(1)
-    p = c.playing()
-    assert p is None, "checking nothing playing when random disabled but playing enabled"
     c.random_enable()
     assert c.random_enabled() == True