Skip to content

Commit

Permalink
Merge pull request #941 from colinin/fix-validator
Browse files Browse the repository at this point in the history
🐛 fix: fixed the validator clock scale
  • Loading branch information
colinin authored Apr 25, 2024
2 parents 2026066 + a88b0cd commit 1e1d93a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
if (redis.call('EXISTS',KEYS[1]) ~= 0) then
redis.call('INCRBY',KEYS[1], 1)
else
redis.call('SETEX',KEYS[1],ARGV[1],1)
redis.call('SET',KEYS[1],1, 'EX', ARGV[1])
end
return tonumber(redis.call('GET',KEYS[1]))
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal void MapDefaultEffectPolicys()
MapEffectPolicy(LimitPolicy.Days, (now, tick) =>
{
// 按天计算应取当天
return (long)(now.Date.AddDays(tick) - DateTime.UtcNow).TotalSeconds;
return (long)(now.Date.AddDays(tick) - now).TotalSeconds;
});

MapEffectPolicy(LimitPolicy.Weeks,(now, tick) =>
Expand All @@ -64,7 +64,7 @@ internal void MapDefaultEffectPolicys()
}
var utcOnceDayOfWeek = nowDate.AddDays(-dayOfWeek);
return (long)(utcOnceDayOfWeek.AddDays(tick * 7) - DateTime.UtcNow).TotalSeconds;
return (long)(utcOnceDayOfWeek.AddDays(tick * 7) - now).TotalSeconds;
});

MapEffectPolicy(LimitPolicy.Month, (now, tick) =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Volo.Abp;

namespace LINGYUN.Abp.Features.LimitValidation
{
Expand Down Expand Up @@ -29,11 +30,11 @@ public RequiresLimitFeatureContext(
int interval = 1,
int limit = 1)
{
Limit = limit;
Policy = policy;
Interval = interval;
LimitFeature = limitFeature;
Options = options;
LimitFeature = limitFeature;
Limit = Check.Positive(limit, nameof(limit));
Interval = Check.Positive(interval, nameof(interval));
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using LINGYUN.Abp.Tests;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;

namespace LINGYUN.Abp.Features.LimitValidation.Redis
Expand All @@ -11,15 +9,5 @@ namespace LINGYUN.Abp.Features.LimitValidation.Redis
typeof(AbpTestsBaseModule))]
public class AbpFeaturesLimitValidationRedisTestModule : AbpModule
{
public override void PreConfigureServices(ServiceConfigurationContext context)
{
var configurationOptions = new AbpConfigurationBuilderOptions
{
BasePath = @"D:\Projects\Development\Abp\FeaturesValidation\Redis",
EnvironmentName = "Development"
};

context.Services.ReplaceConfiguration(ConfigurationHelper.BuildConfiguration(configurationOptions));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ public async Task Should_Not_Allow_To_Call_Method_If_Has_Limit_Feature_Async(str
// it's ok
await TestValidationFeatureClass.Test1MinuteAsync();
await TestValidationFeatureClass.Test1MinuteAsync();
await Assert.ThrowsAsync<AbpFeatureLimitException>(async () =>
{
await TestValidationFeatureClass.Test1MinuteAsync();
});
await Assert.ThrowsAsync<AbpFeatureLimitException>(TestValidationFeatureClass.Test1MinuteAsync);

Thread.Sleep(61000);
await TestValidationFeatureClass.Test1MinuteAsync();
Expand Down

0 comments on commit 1e1d93a

Please sign in to comment.