commit
e21eacd0f7
5 changed files with 98 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using BirdsiteLive.Common.Settings;
|
||||
|
@ -57,6 +58,7 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
{
|
||||
var dbUser = await _twitterUserDal.GetTwitterUserAsync(user.Acct);
|
||||
dbUser.FetchingErrorCount++;
|
||||
dbUser.LastSync = DateTime.UtcNow;
|
||||
|
||||
if (dbUser.FetchingErrorCount > _instanceSettings.FailingTwitterUserCleanUpThreshold)
|
||||
{
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<UserSecretsId>d21486de-a812-47eb-a419-05682bb68856</UserSecretsId>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
<Version>0.19.0</Version>
|
||||
<Version>0.19.1</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace BirdsiteLive.DAL.Postgres.DataAccessLayers
|
|||
|
||||
public async Task<SyncTwitterUser[]> GetAllTwitterUsersAsync(int maxNumber)
|
||||
{
|
||||
var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC LIMIT @maxNumber";
|
||||
var query = $"SELECT * FROM {_settings.TwitterUserTableName} ORDER BY lastSync ASC NULLS FIRST LIMIT @maxNumber";
|
||||
|
||||
using (var dbConnection = Connection)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using BirdsiteLive.DAL.Postgres.DataAccessLayers;
|
||||
|
@ -231,6 +232,39 @@ namespace BirdsiteLive.DAL.Postgres.Tests.DataAccessLayers
|
|||
Assert.IsFalse(result[0].LastTweetSynchronizedForAllFollowersId == default);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllTwitterUsers_Top_NotInit()
|
||||
{
|
||||
// Create accounts
|
||||
var dal = new TwitterUserPostgresDal(_settings);
|
||||
for (var i = 0; i < 1000; i++)
|
||||
{
|
||||
var acct = $"myid{i}";
|
||||
var lastTweetId = i+10;
|
||||
|
||||
await dal.CreateTwitterUserAsync(acct, lastTweetId);
|
||||
}
|
||||
|
||||
// Update accounts
|
||||
var now = DateTime.UtcNow;
|
||||
var allUsers = await dal.GetAllTwitterUsersAsync();
|
||||
foreach (var acc in allUsers)
|
||||
{
|
||||
var lastSync = now.AddDays(acc.LastTweetPostedId);
|
||||
acc.LastSync = lastSync;
|
||||
await dal.UpdateTwitterUserAsync(acc);
|
||||
}
|
||||
|
||||
// Create a not init account
|
||||
await dal.CreateTwitterUserAsync("not_init", -1);
|
||||
|
||||
var result = await dal.GetAllTwitterUsersAsync(10);
|
||||
|
||||
Assert.IsTrue(result.Any(x => x.Acct == "myid0"));
|
||||
Assert.IsTrue(result.Any(x => x.Acct == "myid8"));
|
||||
Assert.IsTrue(result.Any(x => x.Acct == "not_init"));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task GetAllTwitterUsers_Limited()
|
||||
{
|
||||
|
|
|
@ -329,5 +329,64 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
removeTwitterAccountActionMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public async Task ProcessAsync_Unfound_NotInit_Test()
|
||||
{
|
||||
#region Stubs
|
||||
var userId1 = 1;
|
||||
var acct1 = "user1";
|
||||
|
||||
var users = new List<SyncTwitterUser>
|
||||
{
|
||||
new SyncTwitterUser
|
||||
{
|
||||
Id = userId1,
|
||||
Acct = acct1,
|
||||
LastSync = default,
|
||||
LastTweetPostedId = -1,
|
||||
LastTweetSynchronizedForAllFollowersId = -1
|
||||
}
|
||||
};
|
||||
|
||||
var settings = new InstanceSettings
|
||||
{
|
||||
FailingTwitterUserCleanUpThreshold = 300
|
||||
};
|
||||
#endregion
|
||||
|
||||
#region Mocks
|
||||
var twitterUserServiceMock = new Mock<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.GetUser(It.Is<string>(y => y == acct1)))
|
||||
.Returns((TwitterUser)null);
|
||||
|
||||
twitterUserServiceMock
|
||||
.Setup(x => x.PurgeUser(It.Is<string>(y => y == acct1)));
|
||||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.GetTwitterUserAsync(It.Is<string>(y => y == acct1)))
|
||||
.ReturnsAsync(users.First());
|
||||
|
||||
twitterUserDalMock
|
||||
.Setup(x => x.UpdateTwitterUserAsync(
|
||||
It.Is<SyncTwitterUser>(y => y.Id == userId1 && y.FetchingErrorCount == 1 && y.LastSync != default)))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var removeTwitterAccountActionMock = new Mock<IRemoveTwitterAccountAction>(MockBehavior.Strict);
|
||||
#endregion
|
||||
|
||||
var processor = new RefreshTwitterUserStatusProcessor(twitterUserServiceMock.Object, twitterUserDalMock.Object, removeTwitterAccountActionMock.Object, settings);
|
||||
var result = await processor.ProcessAsync(users.ToArray(), CancellationToken.None);
|
||||
|
||||
#region Validations
|
||||
Assert.AreEqual(0, result.Length);
|
||||
|
||||
twitterUserServiceMock.VerifyAll();
|
||||
twitterUserDalMock.VerifyAll();
|
||||
removeTwitterAccountActionMock.VerifyAll();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue