Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 fix: fixed the validator clock scale #941

Merged
merged 1 commit into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 class 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
Loading