Move rate limit example to test/
This commit is contained in:
@@ -58,24 +58,3 @@ int uc_ratelimit_allow(struct RateLimit *r, long current_ts)
|
|||||||
return allowed;
|
return allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
struct RateLimit r;
|
|
||||||
time_t start;
|
|
||||||
|
|
||||||
uc_ratelimit_init(&r, 10, 60, time(NULL));
|
|
||||||
|
|
||||||
for(i = 0; i < 120; i++) {
|
|
||||||
int k;
|
|
||||||
long allowed = 0;
|
|
||||||
sleep(1);
|
|
||||||
for (k = 0; k < 500; k++)
|
|
||||||
allowed += uc_ratelimit_allow(&r, time(NULL));
|
|
||||||
printf("%ld of 500 can pass\n", allowed);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include "ucore/rate_limit.h"
|
||||||
|
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
struct RateLimit r;
|
||||||
|
time_t start;
|
||||||
|
|
||||||
|
uc_ratelimit_init(&r, 10, 60, time(NULL));
|
||||||
|
|
||||||
|
for(i = 0; i < 120; i++) {
|
||||||
|
int k;
|
||||||
|
long allowed = 0;
|
||||||
|
sleep(1);
|
||||||
|
for (k = 0; k < 500; k++)
|
||||||
|
allowed += uc_ratelimit_allow(&r, time(NULL));
|
||||||
|
printf("%ld of 500 can pass\n", allowed);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user