fix: 测试改了一堆bug

This commit is contained in:
zerlei 2024-09-24 17:46:52 +08:00
parent a70a302134
commit ffda80aa01
7 changed files with 113 additions and 86 deletions

View file

@ -2,12 +2,11 @@ namespace Common;
public static class DirExtension public static class DirExtension
{ {
/// <summary>
/// <summary>
/// 比较两个目录文件树是否相同,不相同返回差异部分,左侧是右侧的下一个版本,任何一个节点的nextop != null即所有 /// 比较两个目录文件树是否相同,不相同返回差异部分,左侧是右侧的下一个版本,任何一个节点的nextop != null即所有
/// 节点都会打上标记 /// 节点都会打上标记
/// 文件夹的 NextOp 只有新增和删除 /// 文件夹的 NextOp 只有新增和删除
/// ///
/// </summary> /// </summary>
/// <param name="otherRootDir"></param> /// <param name="otherRootDir"></param>
/// <returns>右侧版本接下来进行的操作</returns> /// <returns>右侧版本接下来进行的操作</returns>
@ -286,14 +285,15 @@ public static class DirExtension
{ {
bool filter(string path) bool filter(string path)
{ {
var relativePath = path.Replace('\\', '/').Replace(thisDir.FormatedPath, "");
if (cherryPicks != null) if (cherryPicks != null)
{ {
return cherryPicks.Contains(path); return cherryPicks.Contains(relativePath);
} }
if (exculdes != null) if (exculdes != null)
{ {
return !exculdes.Contains(path); return !exculdes.Contains(relativePath);
} }
return true; return true;
} }
@ -302,24 +302,27 @@ public static class DirExtension
{ {
throw new NotSupportedException("this dir is not empty."); throw new NotSupportedException("this dir is not empty.");
} }
string[] files = Directory.GetFiles(thisDir.FormatedPath); if (Directory.Exists(thisDir.FormatedPath))
string[] dirs = Directory.GetDirectories(thisDir.FormatedPath);
foreach (var file in files)
{ {
if (filter(file)) string[] files = Directory.GetFiles(thisDir.FormatedPath);
string[] dirs = Directory.GetDirectories(thisDir.FormatedPath);
foreach (var file in files)
{ {
thisDir.Children.Add( if (filter(file))
new File { Path = file, MTime = System.IO.File.GetLastWriteTime($"{file}") } {
); thisDir.Children.Add(
new File { Path = file, MTime = System.IO.File.GetLastWriteTime($"{file}") }
);
}
} }
} foreach (var dir in dirs)
foreach (var dir in dirs)
{
if (filter(dir))
{ {
var ndir = new Dir { Path = dir, Children = [] }; if (filter(dir))
ndir.ExtractInfo(); {
thisDir.Children.Add(ndir); var ndir = new Dir { Path = dir, Children = [] };
ndir.ExtractInfo(cherryPicks, exculdes);
thisDir.Children.Add(ndir);
}
} }
} }
} }

View file

@ -1,4 +1,6 @@
namespace Common; using System.Text.Json.Serialization;
namespace Common;
public enum DirOrFile public enum DirOrFile
{ {
@ -13,7 +15,10 @@ public enum NextOpType
Del = 2 Del = 2
} }
public abstract class AFileOrDir [JsonDerivedType(typeof(AFileOrDir), typeDiscriminator: 1)]
[JsonDerivedType(typeof(File), typeDiscriminator: 2)]
[JsonDerivedType(typeof(Dir), typeDiscriminator: 3)]
public class AFileOrDir
{ {
public DirOrFile Type { get; set; } public DirOrFile Type { get; set; }
public NextOpType? NextOp { get; set; } public NextOpType? NextOp { get; set; }
@ -33,7 +38,11 @@ public abstract class AFileOrDir
get { return Path.Replace("\\", "/"); } get { return Path.Replace("\\", "/"); }
set { Path = value; } set { Path = value; }
} }
public abstract bool IsEqual(AFileOrDir other);
public bool IsEqual(AFileOrDir other)
{
return false;
}
public static int Compare(AFileOrDir l, AFileOrDir r) public static int Compare(AFileOrDir l, AFileOrDir r)
{ {
@ -53,13 +62,14 @@ public abstract class AFileOrDir
/// <param name="mtime">文件的修改时间</param>/ /// <param name="mtime">文件的修改时间</param>/
public class File : AFileOrDir public class File : AFileOrDir
{ {
public File() public File()
{ {
Type = DirOrFile.File; Type = DirOrFile.File;
} }
public required DateTime MTime { get; set; } public required DateTime MTime { get; set; }
public override bool IsEqual(AFileOrDir other) public new bool IsEqual(AFileOrDir other)
{ {
if (other is not File otherFile) if (other is not File otherFile)
{ {
@ -83,9 +93,10 @@ public class Dir : AFileOrDir
{ {
Type = DirOrFile.Dir; Type = DirOrFile.Dir;
} }
public required List<AFileOrDir> Children { get; set; } public required List<AFileOrDir> Children { get; set; }
public override bool IsEqual(AFileOrDir other) public new bool IsEqual(AFileOrDir other)
{ {
if (other is not Dir otherDir) if (other is not Dir otherDir)
{ {

View file

@ -2,6 +2,7 @@ using System.Diagnostics;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
using Common; using Common;
namespace LocalServer; namespace LocalServer;
@ -210,8 +211,11 @@ public class DiffFileAndPackHelper(LocalSyncServer context)
e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes); e.LocalDirInfo.ExtractInfo(e.CherryPicks, e.Excludes);
}); });
//将配置信息发送到remoteServer //将配置信息发送到remoteServer
var options = new JsonSerializerOptions { WriteIndented = true };
Context Context
.RemotePipe.SendMsg(CreateMsg(JsonSerializer.Serialize(Context.NotNullSyncConfig))) .RemotePipe.SendMsg(
CreateMsg(JsonSerializer.Serialize(Context.NotNullSyncConfig, options))
)
.Wait(); .Wait();
} }
@ -275,12 +279,13 @@ public class DeployMSSqlHelper(LocalSyncServer context)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
var arguments = var arguments =
$" /Action:Extract /TargetFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.dacpac " $" /Action:Extract /TargetFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.dacpac"
+ $"/DiagnosticsFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.log " // 不要log file 了
+ $"/p:ExtractAllTableData=false /p:VerifyExtraction=true /SourceServerName:{Context.NotNullSyncConfig.SrcDb.ServerName}" //+ $" /DiagnosticsFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.log"
+ $"/SourceDatabaseName:{Context.NotNullSyncConfig.SrcDb.DatebaseName} /SourceUser:{Context.NotNullSyncConfig.SrcDb.User} " + $" /p:ExtractAllTableData=false /p:VerifyExtraction=true /SourceServerName:{Context.NotNullSyncConfig.SrcDb.ServerName}"
+ $"/SourcePassword:{Context.NotNullSyncConfig.SrcDb.Password} /SourceTrustServerCertificate:{Context.NotNullSyncConfig.SrcDb.TrustServerCertificate} " + $" /SourceDatabaseName:{Context.NotNullSyncConfig.SrcDb.DatebaseName} /SourceUser:{Context.NotNullSyncConfig.SrcDb.User}"
+ $"/p:ExtractReferencedServerScopedElements=False /p:IgnoreUserLoginMappings=True /p:IgnorePermissions=True "; + $" /SourcePassword:{Context.NotNullSyncConfig.SrcDb.Password} /SourceTrustServerCertificate:{Context.NotNullSyncConfig.SrcDb.TrustServerCertificate}"
+ $" /p:ExtractReferencedServerScopedElements=False /p:IgnoreUserLoginMappings=True /p:IgnorePermissions=True";
if (Context.NotNullSyncConfig.SrcDb.SyncTablesData != null) if (Context.NotNullSyncConfig.SrcDb.SyncTablesData != null)
{ {
foreach (var t in Context.NotNullSyncConfig.SrcDb.SyncTablesData) foreach (var t in Context.NotNullSyncConfig.SrcDb.SyncTablesData)
@ -343,7 +348,7 @@ public class UploadPackedHelper(LocalSyncServer context)
Context Context
.LocalPipe.UploadFile( .LocalPipe.UploadFile(
Context.NotNullSyncConfig.RemoteUrl, Context.NotNullSyncConfig.RemoteUrl,
$"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.zip", $"{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}.zip",
(double current) => (double current) =>
{ {
Context Context

View file

@ -100,13 +100,13 @@ public class DiffFileHelper(RemoteSyncServer context)
} }
else else
{ {
var nd = e.LocalDirInfo.Clone(); var nd = new Dir
nd.ResetRootPath( {
Context.NotNullSyncConfig.LocalRootPath, Path = Context.NotNullSyncConfig.RemoteRootPath + e.DirPath,
Context.NotNullSyncConfig.RemoteRootPath Children = []
); };
nd.ExtractInfo(e.CherryPicks, e.Excludes); nd.ExtractInfo(e.CherryPicks, e.Excludes);
e.DiffDirInfo = nd.Diff(nd); e.DiffDirInfo = e.LocalDirInfo.Diff(nd);
e.RemoteDirInfo = nd; e.RemoteDirInfo = nd;
diffConfigs.Add( diffConfigs.Add(
new DirFileConfig { DiffDirInfo = e.DiffDirInfo, DirPath = e.DirPath } new DirFileConfig { DiffDirInfo = e.DiffDirInfo, DirPath = e.DirPath }
@ -149,9 +149,9 @@ public class FinallyPublishHelper(RemoteSyncServer context)
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{ {
var arguments = var arguments =
$"/Action:Publish /SourceFile: {RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac " $" /Action:Publish /SourceFile: {RemoteSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id}/{Context.NotNullSyncConfig.Id}.dacpac"
+ $"/TargetServerName:{Context.NotNullSyncConfig.DstDb.ServerName} /TargetDatabaseName:{Context.NotNullSyncConfig.DstDb.DatebaseName}" + $" /TargetServerName:{Context.NotNullSyncConfig.DstDb.ServerName} /TargetDatabaseName:{Context.NotNullSyncConfig.DstDb.DatebaseName}"
+ $" /TargetUser:{Context.NotNullSyncConfig.DstDb.User} /TargetPassword:{Context.NotNullSyncConfig.DstDb.Password} /TargetTrustServerCertificate:True "; + $" /TargetUser:{Context.NotNullSyncConfig.DstDb.User} /TargetPassword:{Context.NotNullSyncConfig.DstDb.Password} /TargetTrustServerCertificate:True";
ProcessStartInfo startInfo = ProcessStartInfo startInfo =
new() new()
@ -204,7 +204,7 @@ public class FinallyPublishHelper(RemoteSyncServer context)
{ {
if (e.RemoteDirInfo != null && e.DiffDirInfo != null) if (e.RemoteDirInfo != null && e.DiffDirInfo != null)
{ {
e.RemoteDirInfo.Combine(DirFileOp, e.DiffDirInfo,false,true); e.RemoteDirInfo.Combine(DirFileOp, e.DiffDirInfo, false, true);
} }
}); });

View file

@ -11,7 +11,7 @@ public class PipeSeed : IDisposable
TestConfig = new Config TestConfig = new Config
{ {
Name = "Test", Name = "Test",
RemoteUrl = "D:/FileSyncTest", RemoteUrl = "D:/FileSyncTest/dtemp",
RemotePwd = "t123", RemotePwd = "t123",
IsDeployDb = true, IsDeployDb = true,
IsDeployProject = true, IsDeployProject = true,

View file

@ -13,46 +13,48 @@ public class PipeTest
[Fact] [Fact]
public async void TestCase() public async void TestCase()
{ {
// var p1 = new TestPipe(false, "1"); var p1 = new TestPipe(false, "1");
// var x = Task.Run(async () => var x = Task.Run(async () =>
// { {
// var rs = p1.Work( var rs = p1.Work(
// (byte[] b) => (byte[] b) =>
// { {
// Console.WriteLine(b); Console.WriteLine(b);
// return true; return true;
// } }
// ); );
// await foreach (var r in rs) await foreach (var r in rs)
// { {
// Console.WriteLine(r); Console.WriteLine(r);
// } }
// }); });
// //await p1.Close("sdf"); //await p1.Close("sdf");
// //await x; //await x;
// var p2 = new TestPipe(false, "2"); var p2 = new TestPipe(false, "2");
// p1.Other = p2; p1.Other = p2;
// p2.Other = p1; p2.Other = p1;
// var p3 = new TestPipe(true, "3"); var p3 = new TestPipe(true, "3");
// var p4 = new TestPipe(true, "4"); var p4 = new TestPipe(true, "4");
// p3.Other = p4; p3.Other = p4;
// p4.Other = p3; p4.Other = p3;
// RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")]; LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
// var lf = new LocalSyncServerFactory(); RemoteSyncServer.TempRootFile = "D:/FileSyncTest/dtemp";
// lf.CreateLocalSyncServer(p2, "Test", p3); RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
// var rf = new RemoteSyncServerFactory(); var lf = new LocalSyncServerFactory();
// rf.CreateRemoteSyncServer(p4, "Test"); lf.CreateLocalSyncServer(p2, "Test", p3);
// var starter = new SyncMsg var rf = new RemoteSyncServerFactory();
// { rf.CreateRemoteSyncServer(p4, "Test");
// Body = JsonSerializer.Serialize(new PipeSeed().TestConfig), var starter = new SyncMsg
// Type = SyncMsgType.General, {
// Step = SyncProcessStep.Connect Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
// }; Type = SyncMsgType.General,
// await p1.SendMsg(starter); Step = SyncProcessStep.Connect
// await x; };
// if (p1.ErrResult != null) await p1.SendMsg(starter);
// { await x;
// Assert.Fail(p1.ErrResult); if (p1.ErrResult != null)
// } {
Assert.Fail(p1.ErrResult);
}
} }
} }

View file

@ -2,6 +2,7 @@
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using Common; using Common;
using RemoteServer;
namespace ServerTest namespace ServerTest
{ {
@ -25,14 +26,19 @@ namespace ServerTest
} }
public override async Task UploadFile( public override async Task UploadFile(
string filePath,
string dst, string dst,
string filePath,
Func<double, bool> progressCb Func<double, bool> progressCb
) )
{ {
dst = Path.Combine(RemoteSyncServer.TempRootFile, Path.GetFileName(filePath));
await Task.Run(() => await Task.Run(() =>
{ {
progressCb(100); progressCb(100);
//if (!Directory.Exists(dst))
//{
// Directory.CreateDirectory(dst);
//}
System.IO.File.Copy(filePath, dst, true); System.IO.File.Copy(filePath, dst, true);
}); });
} }