Browse Source
Merge pull request #941 from colinin/fix-validator
🐛 fix: fixed the validator clock scale
pull/955/head
yx lin
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
8 additions and
22 deletions
-
aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation.Redis/LINGYUN/Abp/Features/LimitValidation/Redis/Lua/process.lua
-
aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/AbpFeaturesLimitValidationOptions.cs
-
aspnet-core/framework/common/LINGYUN.Abp.Features.LimitValidation/LINGYUN/Abp/Features/LimitValidation/RequiresLimitFeatureContext.cs
-
aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Redis.Tests/LINGYUN/Abp/Features/LimitValidation/Redis/AbpFeaturesLimitValidationRedisTestModule.cs
-
aspnet-core/tests/LINGYUN.Abp.Features.LimitValidation.Tests/LINGYUN/Abp/Features/LimitValidation/FeaturesLimitValidationTests.cs
|
|
|
@ -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])) |
|
|
|
@ -50,7 +50,7 @@ namespace LINGYUN.Abp.Features.LimitValidation |
|
|
|
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) => |
|
|
|
@ -64,7 +64,7 @@ namespace LINGYUN.Abp.Features.LimitValidation |
|
|
|
} |
|
|
|
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) => |
|
|
|
|
|
|
|
@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using Volo.Abp; |
|
|
|
|
|
|
|
namespace LINGYUN.Abp.Features.LimitValidation |
|
|
|
{ |
|
|
|
@ -29,11 +30,11 @@ namespace LINGYUN.Abp.Features.LimitValidation |
|
|
|
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>
|
|
|
|
|
|
|
|
@ -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 |
|
|
|
@ -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)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -27,10 +27,7 @@ namespace LINGYUN.Abp.Features.LimitValidation |
|
|
|
// 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(); |
|
|
|
|