Github user DaanHoogland commented on a diff in the pull request:

    https://github.com/apache/cloudstack/pull/1445#discussion_r56799125
  
    --- Diff: utils/src/test/java/com/cloud/utils/TestProfiler.java ---
    @@ -19,84 +19,79 @@
     
     package com.cloud.utils;
     
    -import org.apache.log4j.Logger;
     import org.junit.Assert;
    +import org.junit.Before;
     import org.junit.Test;
    +import org.junit.runner.RunWith;
    +import org.powermock.api.mockito.PowerMockito;
    +import org.powermock.core.classloader.annotations.PrepareForTest;
    +import org.powermock.modules.junit4.PowerMockRunner;
     
     import com.cloud.utils.testcase.Log4jEnabledTestCase;
     
    +@RunWith(PowerMockRunner.class)
    +@PrepareForTest({Profiler.class})
     public class TestProfiler extends Log4jEnabledTestCase {
    -    protected final static Logger s_logger = 
Logger.getLogger(TestProfiler.class);
     
    -    private static final long MILLIS_FACTOR = 1000l;
    -    private static final int MARGIN = 100;
    -    // Profiler uses System.nanoTime which is not reliable on the 
millisecond
    -    // A sleep of 1000 milliseconds CAN be measured as 999 milliseconds
    -    // Therefore make the second larger, by 10% of the margin
    -    private static final long ONE_SECOND = 1000l + (MARGIN / 10);
    -    private static final double EXPONENT = 3d;
    +    private static final long SLEEP_TIME_NANO = 1000000000L;
    +    private static Profiler pf;
    +
    +    @Before
    +    public void setUp() {
    +        pf = new Profiler();
    +        PowerMockito.mockStatic(System.class);
    +        PowerMockito.when(System.nanoTime()).thenReturn(0L, 
SLEEP_TIME_NANO);
    --- End diff --
    
    mocking the system return of the time does not seem right to me. it will be 
returning the same in start() and in stop(), don't you agree?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to