tests/auto/qtipc/lackey/scripts/consumer.js
branchRCL_3
changeset 7 3f74d0d4af4c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/auto/qtipc/lackey/scripts/consumer.js	Thu Apr 08 14:19:33 2010 +0300
@@ -0,0 +1,41 @@
+function QVERIFY(x, debugInfo) {
+    if (!(x)) {
+        print(debugInfo);
+        throw(debugInfo);
+    }
+}
+
+var consumer = new ScriptSharedMemory;
+consumer.setKey("market");
+
+//print("consumer starting");
+var tries = 0;;
+while(!consumer.attach()) {
+    if (tries == 5000) {
+        var message = "consumer exiting, waiting too long";
+        print(message);
+        throw(message);
+    }
+    ++tries;
+    consumer.sleep(1);
+}
+//print("consumer attached");
+
+
+var i = 0;
+while(true) {
+    QVERIFY(consumer.lock(), "lock");
+    if (consumer.get(0) == 'Q') {
+        consumer.set(0, ++i);
+        //print ("consumer sets" + i);
+    }
+    if (consumer.get(0) == 'E') {
+        QVERIFY(consumer.unlock(), "unlock");
+        break;
+    }
+    QVERIFY(consumer.unlock(), "unlock");
+    consumer.sleep(10);
+}
+
+//print("consumer detaching");
+QVERIFY(consumer.detach());