Slightly more verbose tests.
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);
}
/** @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,
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:
* 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 */
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;
}
#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);
char **vec,
int nvec) {
struct kvp *actiondata = 0;
- char *id;
+ const char *id;
/* Standard fields */
kvp_set(&actiondata, "who", c->who);
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"
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"
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")
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"
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",
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"
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",
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"
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)
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"