Skip to content

Commit

Permalink
Improve test case for poor-performing machine. (sofastack#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjboy authored Apr 12, 2018
1 parent 83a6e8d commit a30a3bf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,8 @@ static int delayGetWeight(final ProviderInfo providerInfo, int expect, int n50ms
public Integer call() throws Exception {
return ProviderInfoWeightManager.getWeight(providerInfo);
}
}, expect, 50, n50ms);
}, expect, 70, n50ms);
// 本来应该是50ms,我们把50改为70。是因为如果测试机器性能太差,间隔太小会等不到数据
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,8 @@ public void testRegulationEffective() throws InterruptedException {
Assert.assertTrue(invocationStat.getExceptionRate() == 0.2);

/**第一个窗口时间到达,被降级*/
Thread.sleep(2600);
int appWeight = ProviderInfoWeightManager.getWeight(providerInfo);
Assert.assertEquals(50, appWeight);
// 第一个窗口结束
Assert.assertTrue(50 == delayGetWeight(providerInfo, 50, 52));
InvocationStatFactory.removeInvocationStat(invocationStat);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@ public void test() throws InterruptedException {
Assert.assertEquals(2, invocationStat.getExceptionCount());
Assert.assertTrue(0.2D == invocationStat.getExceptionRate());

Thread.sleep(2100);//第一个窗口结束

int appWeight = ProviderInfoWeightManager.getWeight(providerInfo);
Assert.assertEquals(50, appWeight);
//第一个窗口结束
Assert.assertEquals(50, delayGetWeight(providerInfo, 50, 42));

/**test recover normal*/
config.setLeastWindowCount(6L);
Expand All @@ -76,10 +74,8 @@ public void test() throws InterruptedException {
Assert.assertTrue(invocationStat.getExceptionCount() == 1);
Assert.assertTrue(invocationStat.getExceptionRate() == 0.13);

Thread.sleep(3100);//第二个窗口结束

int appWeight2 = ProviderInfoWeightManager.getWeight(providerInfo);
Assert.assertTrue(appWeight2 == 90);
//第二个窗口结束
Assert.assertTrue(90 == delayGetWeight(providerInfo, 90, 62));

/**test recover max*/
for (int i = 0; i < 7; i++) {
Expand All @@ -95,10 +91,7 @@ public void test() throws InterruptedException {
Assert.assertTrue(invocationStat.getExceptionRate() == 0.29);

Thread.sleep(2100);//第三个窗口结束

Integer appWeight3 = ProviderInfoWeightManager.getWeight(providerInfo);
Assert.assertEquals(appWeight3.intValue(), 100);
Assert.assertTrue(100 == delayGetWeight(providerInfo, 100, 42));
InvocationStatFactory.removeInvocationStat(invocationStat);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.junit.Assert;
import org.junit.Test;

import java.util.concurrent.Callable;

/**
*
*
Expand Down Expand Up @@ -51,12 +53,16 @@ public void testAll() throws InterruptedException {
}
Thread.sleep(100);
final ProviderInfo providerInfo = getProviderInfoByHost(consumerConfig, "127.0.0.1");
InvocationStatDimension statDimension = new InvocationStatDimension(providerInfo, consumerConfig);
final InvocationStatDimension statDimension = new InvocationStatDimension(providerInfo, consumerConfig);
InvocationStat invocationStat = InvocationStatFactory.ALL_STATS.get(statDimension);
Assert.assertNotNull(invocationStat);

Thread.sleep(8000);
invocationStat = InvocationStatFactory.ALL_STATS.get(statDimension);
Assert.assertNull(invocationStat);
// 最多等10000ms 到了下一个周期
Assert.assertNull(delayGet(new Callable<InvocationStat>() {
@Override
public InvocationStat call() throws Exception {
return InvocationStatFactory.ALL_STATS.get(statDimension);
}
}, null, 100, 100));
}
}

0 comments on commit a30a3bf

Please sign in to comment.