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,7 +2,6 @@ namespace Common;
public static class DirExtension public static class DirExtension
{ {
/// <summary> /// <summary>
/// 比较两个目录文件树是否相同,不相同返回差异部分,左侧是右侧的下一个版本,任何一个节点的nextop != null即所有 /// 比较两个目录文件树是否相同,不相同返回差异部分,左侧是右侧的下一个版本,任何一个节点的nextop != null即所有
/// 节点都会打上标记 /// 节点都会打上标记
@ -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,6 +302,8 @@ public static class DirExtension
{ {
throw new NotSupportedException("this dir is not empty."); throw new NotSupportedException("this dir is not empty.");
} }
if (Directory.Exists(thisDir.FormatedPath))
{
string[] files = Directory.GetFiles(thisDir.FormatedPath); string[] files = Directory.GetFiles(thisDir.FormatedPath);
string[] dirs = Directory.GetDirectories(thisDir.FormatedPath); string[] dirs = Directory.GetDirectories(thisDir.FormatedPath);
foreach (var file in files) foreach (var file in files)
@ -318,11 +320,12 @@ public static class DirExtension
if (filter(dir)) if (filter(dir))
{ {
var ndir = new Dir { Path = dir, Children = [] }; var ndir = new Dir { Path = dir, Children = [] };
ndir.ExtractInfo(); ndir.ExtractInfo(cherryPicks, exculdes);
thisDir.Children.Add(ndir); thisDir.Children.Add(ndir);
} }
} }
} }
}
public static void AddChild(this Dir thisDir, AFileOrDir child) public static void AddChild(this Dir thisDir, AFileOrDir child)
{ {

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)
{ {
@ -57,9 +66,10 @@ public class File : AFileOrDir
{ {
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();
} }
@ -276,7 +280,8 @@ public class DeployMSSqlHelper(LocalSyncServer context)
{ {
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 了
//+ $" /DiagnosticsFile:{LocalSyncServer.TempRootFile}/{Context.NotNullSyncConfig.Id.ToString()}/{Context.NotNullSyncConfig.Id.ToString()}.log"
+ $" /p:ExtractAllTableData=false /p:VerifyExtraction=true /SourceServerName:{Context.NotNullSyncConfig.SrcDb.ServerName}" + $" /p:ExtractAllTableData=false /p:VerifyExtraction=true /SourceServerName:{Context.NotNullSyncConfig.SrcDb.ServerName}"
+ $" /SourceDatabaseName:{Context.NotNullSyncConfig.SrcDb.DatebaseName} /SourceUser:{Context.NotNullSyncConfig.SrcDb.User}" + $" /SourceDatabaseName:{Context.NotNullSyncConfig.SrcDb.DatebaseName} /SourceUser:{Context.NotNullSyncConfig.SrcDb.User}"
+ $" /SourcePassword:{Context.NotNullSyncConfig.SrcDb.Password} /SourceTrustServerCertificate:{Context.NotNullSyncConfig.SrcDb.TrustServerCertificate}" + $" /SourcePassword:{Context.NotNullSyncConfig.SrcDb.Password} /SourceTrustServerCertificate:{Context.NotNullSyncConfig.SrcDb.TrustServerCertificate}"
@ -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 }

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;
// var p2 = new TestPipe(false, "2");
// p1.Other = p2;
// p2.Other = p1;
// var p3 = new TestPipe(true, "3");
// var p4 = new TestPipe(true, "4");
// p3.Other = p4;
// p4.Other = p3;
// RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
// var lf = new LocalSyncServerFactory();
// lf.CreateLocalSyncServer(p2, "Test", p3);
// var rf = new RemoteSyncServerFactory();
// rf.CreateRemoteSyncServer(p4, "Test");
// var starter = new SyncMsg
// {
// Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
// Type = SyncMsgType.General,
// Step = SyncProcessStep.Connect
// };
// await p1.SendMsg(starter);
//await x; //await x;
// if (p1.ErrResult != null) var p2 = new TestPipe(false, "2");
// { p1.Other = p2;
// Assert.Fail(p1.ErrResult); p2.Other = p1;
// } var p3 = new TestPipe(true, "3");
var p4 = new TestPipe(true, "4");
p3.Other = p4;
p4.Other = p3;
LocalSyncServer.TempRootFile = "D:/FileSyncTest/stemp";
RemoteSyncServer.TempRootFile = "D:/FileSyncTest/dtemp";
RemoteSyncServerFactory.NamePwd = [new Tuple<string, string>("Test", "t123")];
var lf = new LocalSyncServerFactory();
lf.CreateLocalSyncServer(p2, "Test", p3);
var rf = new RemoteSyncServerFactory();
rf.CreateRemoteSyncServer(p4, "Test");
var starter = new SyncMsg
{
Body = JsonSerializer.Serialize(new PipeSeed().TestConfig),
Type = SyncMsgType.General,
Step = SyncProcessStep.Connect
};
await p1.SendMsg(starter);
await x;
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);
}); });
} }