def testRapidChanges(self): """ Description This test verifies that the subscriber library doesn't emit unnecessary valueChanged signals (in spite of receiving multiple D-Bus messages in the same main loop iteration). Steps 1. starts up a provider with one property 2. starts a client, verifies that the value arrives 3. suspends the client (so it stops processing D-Bus messages) 4. sets new value for the property twice in the provider 5. resumes the client 6. verifies that the client receives only one valueChanged signal """ provider_fast = CLTool("context-provide", "--v2", "com.nokia.fast", "int","test.fast","44") provider_fast.expect("Setting key") context_client = CLTool("context-listen", "test.fast") self.assert_(context_client.expect(wanted("test.fast", "int", "44")), "Bad value for the fast property, wanted 44") context_client.suspend() provider_fast.send("test.fast = 34") provider_fast.expect("Setting key") provider_fast.send("test.fast = 54") provider_fast.expect("Setting key") context_client.resume() context_client.expect(wanted("test.fast", "int", "54")) # the two value changes can happen very close in time, so we # have to check that beyond the good value there are no other # value(s) if len(re.findall("test.fast =", context_client.last_output)) != 1: context_client.printio() self.assert_(False, "expected a single valueChanged") # not even after waiting one second self.assertFalse(context_client.expect("test.fast =", wantdump = False, timeout=1), "expected a single valueChanged") context_client.wait() provider_fast.wait()
def testAsynchronicity(self): """ Description This test verifies that the asynchronicity of the subscriber library Pre-conditions 2 Providers started with context-provide tool. Each provider offers one property. 1 provider is delayed (3s). Steps Subscribe to both properties Verify that return values are correct Measure the time elapsed between the reception of the 2 values. Post-conditions Kill providers References None """ # start the client provider_slow = CLTool("context-provide", "--v2", "com.nokia.slow", "int","test.slow","42") provider_slow.expect("Setting key") # wait for it provider_fast = CLTool("context-provide", "--v2", "com.nokia.fast", "int","test.fast","44") provider_fast.expect("Setting key") # wait for it context_client = CLTool("context-listen") context_client.expect("Available commands") # wait for it provider_slow.comment("provider_slow sleep time started at" + str(time.time())) provider_slow.send("sleep 3") provider_slow.expect("Sleeping") # wait for it context_client.send("n test.slow ; n test.fast") # check the fast property self.assert_(context_client.expect(wanted("test.fast", "int", "44")), # timeout == 3 seconds "Bad value for the fast property, wanted 44") fast_time = time.time() context_client.comment("Fast property arrived with good value at: " + str(fast_time)) # check the slow property self.assert_(context_client.expect(wanted("test.slow", "int", "42")), # timeout == 10 seconds max, but 5 is enough usually "Bad value for the slow property, wanted 42") slow_time = time.time() context_client.comment("Slow property arrived with good value at: " + str(slow_time)) if slow_time - fast_time < 1.5: provider_slow.printio() context_client.printio() self.assert_(False, "The arrival time of the fast and slow property is not far enough from each other") # context_client.printio() context_client.wait() provider_fast.wait() provider_slow.wait()