def testCommanderFunctionality(self):
        provider = CLTool("context-provide", "--v2", "com.nokia.test", "int", "test.int", "42")
        provider.send("dump")
        provider.expect("Wrote") # wait for it

        listen = CLTool("context-listen", "test.int")

        self.assert_(listen.expect(wanted("test.int", "int", "42")),
                     "Bad value initially from the real provider, wanted 42")

        commander =  CLTool("context-provide", "--v2")
        commander.send("add int test.int 4242")
        commander.send("start")
        commander.expect("Added") # wait for it

        self.assert_(listen.expect(wanted("test.int", "int", "4242")),
                     "Value after commander has been started is wrong, wanted 4242")

        commander.send("unset test.int")
        listen.comment("commander commanded test.int to unknown")
        self.assert_(listen.expect(wantedUnknown("test.int")),
                     "Value after commander has changed it to unknown is wrong")

        commander.send("test.int = 1235")
        self.assert_(listen.expect(wanted("test.int", "int", "1235")),
                     "Value after commander has changed it is wrong, wanted 1235")

        commander.wait()
        listen.comment("Commander killed")
        self.assert_(listen.expect(wanted("test.int", "int", "42")),
                     "Value after killing the commander is wrong, wanted 42")
        listen.wait()
        provider.wait()
Пример #2
0
    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()