qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chuck Rolke <cro...@redhat.com>
Subject Re: [1/3] qpid-proton git commit: NO-JIRA: c++: Speed up recurring_timer example.
Date Wed, 11 Nov 2015 15:54:52 GMT
This commit seems a bit heavy to be NO-JIRA as it breaks my windows builds several ways.

Compile error:
=============
fixed

Syntax error:
============
Python 2.6.1 complains about:

13:   File "C:/Jenkins/workspace/proton-c-master-windows/examples/cpp/example_test.py", line
228
13:     env = {k: v for k,v in os.environ.iteritems() if k != "VALGRIND"}
13:                   ^

Python 2.7.1 is fine with this. 2.6 works with simpler iteration constructs.

Self test fail:
==============
The test_recurring_time (on my single try) fails with an extra "Tock..." after the first "Tick...".

-Chuck


----- Original Message -----
> From: aconway@apache.org
> To: commits@qpid.apache.org
> Sent: Tuesday, November 10, 2015 5:43:51 PM
> Subject: [1/3] qpid-proton git commit: NO-JIRA: c++: Speed up recurring_timer example.
> 
> Repository: qpid-proton
> Updated Branches:
>   refs/heads/master 1b1b2e596 -> 01e136cc6
> 
> 
> NO-JIRA: c++: Speed up recurring_timer example.
> 
> 
> Project: http://git-wip-us.apache.org/repos/asf/qpid-proton/repo
> Commit: http://git-wip-us.apache.org/repos/asf/qpid-proton/commit/b131dc19
> Tree: http://git-wip-us.apache.org/repos/asf/qpid-proton/tree/b131dc19
> Diff: http://git-wip-us.apache.org/repos/asf/qpid-proton/diff/b131dc19
> 
> Branch: refs/heads/master
> Commit: b131dc199f7f2c69a14587e45b6feaf741b53610
> Parents: 1b1b2e5
> Author: Alan Conway <aconway@redhat.com>
> Authored: Thu Nov 5 10:22:49 2015 -0500
> Committer: Alan Conway <aconway@redhat.com>
> Committed: Tue Nov 10 17:06:27 2015 -0500
> 
> ----------------------------------------------------------------------
>  examples/cpp/CMakeLists.txt      |  2 +-
>  examples/cpp/example_test.py     | 17 ++++++++++++++---
>  examples/cpp/recurring_timer.cpp | 29 ++++++++++++++---------------
>  3 files changed, 29 insertions(+), 19 deletions(-)
> ----------------------------------------------------------------------
> 
> 
> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b131dc19/examples/cpp/CMakeLists.txt
> ----------------------------------------------------------------------
> diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
> index 3e5dafe..8916963 100644
> --- a/examples/cpp/CMakeLists.txt
> +++ b/examples/cpp/CMakeLists.txt
> @@ -60,7 +60,7 @@ else(WIN32)
>  endif(WIN32)
>  
>  add_test(NAME cpp_example_test
> -  COMMAND ${PYTHON_EXECUTABLE} ${env_py} -- "PATH=${test_path}"
> "PYTHONPATH=${CMAKE_CURRENT_SOURCE_DIR}" ${VALGRIND_ENV}
> ${PYTHON_EXECUTABLE} -m unittest -v example_test)
> +  COMMAND ${PYTHON_EXECUTABLE} ${env_py} -- "PATH=${test_path}"
> ${VALGRIND_ENV} ${PYTHON_EXECUTABLE}
> ${CMAKE_CURRENT_SOURCE_DIR}/example_test.py -v)
>  
>  set(broker_tests example_test.ExampleTest.test_request_response
>  example_test.ExampleTest.test_simple_send_recv)
>  
> 
> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b131dc19/examples/cpp/example_test.py
> ----------------------------------------------------------------------
> diff --git a/examples/cpp/example_test.py b/examples/cpp/example_test.py
> index 3ed8b9c..f51cf57 100644
> --- a/examples/cpp/example_test.py
> +++ b/examples/cpp/example_test.py
> @@ -23,6 +23,7 @@ import unittest
>  import os, sys, socket, time
>  from  random import randrange
>  from subprocess import Popen, PIPE, STDOUT
> +from copy import copy
>  import platform
>  
>  def cmdline(*args):
> @@ -215,14 +216,24 @@ Values: map{string(k1):int(42),
> symbol(k2):boolean(false)}
>          self.assertEqual(expect, execute("encode_decode"))
>  
>      def test_recurring_timer(self):
> -        expect="""Tick...
> +        # Disable valgrind, this test is time-sensitive.
> +        env = {k: v for k,v in os.environ.iteritems() if k != "VALGRIND"}
> +        env, os.environ = os.environ, env
> +        try:
> +            expect="""Tick...
> +Tick...
> +Tock...
> +Tick...
> +Tock...
>  Tick...
>  Tock...
>  Tick...
>  Tock...
>  """
> -        self.maxDiff = None
> -        self.assertEqual(expect, execute("recurring_timer", "-t", "3"))
> +            self.maxDiff = None
> +            self.assertEqual(expect, execute("recurring_timer", "-t", ".01",
> "-k", ".001"))
> +        finally:
> +            os.environ = env    # Restore environment
>  
>  if __name__ == "__main__":
>      unittest.main()
> 
> http://git-wip-us.apache.org/repos/asf/qpid-proton/blob/b131dc19/examples/cpp/recurring_timer.cpp
> ----------------------------------------------------------------------
> diff --git a/examples/cpp/recurring_timer.cpp
> b/examples/cpp/recurring_timer.cpp
> index b6141fd..37cbfed 100644
> --- a/examples/cpp/recurring_timer.cpp
> +++ b/examples/cpp/recurring_timer.cpp
> @@ -43,53 +43,52 @@ class tocker : public proton::messaging_handler {
>  
>  class recurring : public proton::messaging_handler {
>    private:
> -    int remaining_secs;
> +    int remaining_msecs, tick_ms;
>      ticker tick_handler;
>      tocker tock_handler;
>      proton::task *cancel_task;
>    public:
>  
> -    recurring(int secs) : remaining_secs(secs), cancel_task(0) {}
> +    recurring(int msecs, int tickms) : remaining_msecs(msecs),
> tick_ms(tickms), cancel_task(0) {}
>  
>      proton::task& ticktock(proton::event &e) {
>          // Show timer events in separate handlers.
> -        e.container().schedule(250, &tick_handler);
> -        return e.container().schedule(750, &tock_handler);
> +        e.container().schedule(tick_ms, &tick_handler);
> +        return e.container().schedule(tick_ms * 3, &tock_handler);
>      }
>  
>      void on_start(proton::event &e) {
> -        if (remaining_secs <= 0)
> +        if (remaining_msecs <= 0)
>              return;
>          proton::task& first_tock = ticktock(e);
> -        e.container().schedule(1000);
> -        remaining_secs--;
>          // Show a cancel operation.
>          cancel_task = &first_tock;
> -        e.container().schedule(500);
> +        e.container().schedule(tick_ms);
>      }
>  
>      void on_timer_task(proton::event &e) {
>          if (cancel_task) {
>              cancel_task->cancel();
>              cancel_task = 0;
> -            return;
>          }
> -        if (remaining_secs) {
> +        remaining_msecs -= tick_ms * 2;
> +        if (remaining_msecs > 0) {
>              ticktock(e);
> -            e.container().schedule(1000);
> -            remaining_secs--;
> +            e.container().schedule(tick_ms * 4);
>          }
>      }
>  };
>  
>  int main(int argc, char **argv) {
>      // Command line options
> -    int running_time_in_secs = 5;
> +    double running_time = 5;
> +    double tick = 0.25;
>      options opts(argc, argv);
> -    opts.add_value(running_time_in_secs, 't', "running time", "running time
> in seconds", "RUNTIME");
> +    opts.add_value(running_time, 't', "running time", "running time in
> seconds", "RUNTIME");
> +    opts.add_value(tick, 'k', "tick time", "tick time as fraction of
> second", "TICK");
>      try {
>          opts.parse();
> -        recurring recurring_handler(running_time_in_secs);
> +        recurring recurring_handler(running_time * 1000, tick * 1000);
>          proton::container(recurring_handler).run();
>          return 0;
>      } catch (const bad_option& e) {
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
> For additional commands, e-mail: commits-help@qpid.apache.org
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org


Mime
View raw message