Skip to content

Commit

Permalink
Merge pull request #73195 from CyrusNajmabadi/solutionAsserts
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi authored Apr 23, 2024
2 parents c5b98ae + cacc40f commit 8a6ff11
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public async Task TestAssetSynchronization()
// build checksum
await solution.CompilationState.GetChecksumAsync(CancellationToken.None);

var map = await solution.GetAssetMapAsync(CancellationToken.None);
var map = await solution.GetAssetMapAsync(projectConeId: null, CancellationToken.None);

using var remoteWorkspace = CreateRemoteWorkspace();

Expand Down Expand Up @@ -104,7 +104,7 @@ public async Task TestSolutionSynchronization()
// build checksum
await solution.CompilationState.GetChecksumAsync(CancellationToken.None);

var map = await solution.GetAssetMapAsync(CancellationToken.None);
var map = await solution.GetAssetMapAsync(projectConeId: null, CancellationToken.None);

using var remoteWorkspace = CreateRemoteWorkspace();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ private static void VerifyStates(Solution solution1, Solution solution2, string

private static async Task VerifyAssetStorageAsync(InProcRemoteHostClient client, Solution solution)
{
var map = await solution.GetAssetMapAsync(CancellationToken.None);
var map = await solution.GetAssetMapAsync(projectConeId: null, CancellationToken.None);

var storage = client.TestData.WorkspaceManager.SolutionAssetCache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ public async Task FindAsync<TArg>(
await ChecksumCollection.FindAsync(assetPath, state.AnalyzerConfigDocumentStates, searchingChecksumsLeft, onAssetFound, arg, cancellationToken).ConfigureAwait(false);
}
}

public override string ToString()
=> $"ProjectStateChecksums({ProjectId})";
}

internal sealed class DocumentStateChecksums(
Expand Down Expand Up @@ -526,6 +529,9 @@ public async Task FindAsync<TArg>(
onAssetFound(Text, text, arg);
}
}

public override string ToString()
=> $"DocumentStateChecksums({DocumentId})";
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ private async Task ValidateChecksumAsync(
var workspace = new AdhocWorkspace(_hostServices);
workspace.AddSolution(solutionInfo);

await TestUtils.AssertChecksumsAsync(_assetProvider, checksumFromRequest, workspace.CurrentSolution, incrementalSolutionBuilt).ConfigureAwait(false);
await TestUtils.AssertChecksumsAsync(_assetProvider, checksumFromRequest, workspace.CurrentSolution, incrementalSolutionBuilt, projectConeId).ConfigureAwait(false);
}
#endif
}
Expand Down
25 changes: 13 additions & 12 deletions src/Workspaces/Remote/ServiceHub/Host/TestUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,43 +40,44 @@ internal static async Task AssertChecksumsAsync(
AssetProvider assetService,
Checksum checksumFromRequest,
Solution solutionFromScratch,
Solution incrementalSolutionBuilt)
Solution incrementalSolutionBuilt,
ProjectId? projectConeId)
{
#if DEBUG
var sb = new StringBuilder();
var allChecksumsFromRequest = await GetAllChildrenChecksumsAsync(checksumFromRequest).ConfigureAwait(false);

var assetMapFromNewSolution = await solutionFromScratch.GetAssetMapAsync(CancellationToken.None).ConfigureAwait(false);
var assetMapFromIncrementalSolution = await incrementalSolutionBuilt.GetAssetMapAsync(CancellationToken.None).ConfigureAwait(false);
var assetMapFromNewSolution = await solutionFromScratch.GetAssetMapAsync(projectConeId, CancellationToken.None).ConfigureAwait(false);
var assetMapFromIncrementalSolution = await incrementalSolutionBuilt.GetAssetMapAsync(projectConeId, CancellationToken.None).ConfigureAwait(false);

// check 4 things
// 1. first see if we create new solution from scratch, it works as expected (indicating a bug in incremental update)
var mismatch1 = assetMapFromNewSolution.Where(p => !allChecksumsFromRequest.Contains(p.Key)).ToList();
AppendMismatch(mismatch1, "assets only in new solutoin but not in the request", sb);
AppendMismatch(mismatch1, "Assets only in new solution but not in the request", sb);

// 2. second check what items is mismatching for incremental solution
var mismatch2 = assetMapFromIncrementalSolution.Where(p => !allChecksumsFromRequest.Contains(p.Key)).ToList();
AppendMismatch(mismatch2, "assets only in the incremental solution but not in the request", sb);
AppendMismatch(mismatch2, "Assets only in the incremental solution but not in the request", sb);

// 3. check whether solution created from scratch and incremental one have any mismatch
var mismatch3 = assetMapFromNewSolution.Where(p => !assetMapFromIncrementalSolution.ContainsKey(p.Key)).ToList();
AppendMismatch(mismatch3, "assets only in new solution but not in incremental solution", sb);
AppendMismatch(mismatch3, "Assets only in new solution but not in incremental solution", sb);

var mismatch4 = assetMapFromIncrementalSolution.Where(p => !assetMapFromNewSolution.ContainsKey(p.Key)).ToList();
AppendMismatch(mismatch4, "assets only in incremental solution but not in new solution", sb);
AppendMismatch(mismatch4, "Assets only in incremental solution but not in new solution", sb);

// 4. see what item is missing from request
var mismatch5 = await GetAssetFromAssetServiceAsync(allChecksumsFromRequest.Except(assetMapFromNewSolution.Keys)).ConfigureAwait(false);
AppendMismatch(mismatch5, "assets only in the request but not in new solution", sb);
AppendMismatch(mismatch5, "Assets only in the request but not in new solution", sb);

var mismatch6 = await GetAssetFromAssetServiceAsync(allChecksumsFromRequest.Except(assetMapFromIncrementalSolution.Keys)).ConfigureAwait(false);
AppendMismatch(mismatch6, "assets only in the request but not in incremental solution", sb);
AppendMismatch(mismatch6, "Assets only in the request but not in incremental solution", sb);

var result = sb.ToString();
if (result.Length > 0)
{
Logger.Log(FunctionId.SolutionCreator_AssetDifferences, result);
Debug.Fail("Differences detected in solution checksum: " + result);
Debug.Fail($"Differences detected in solution checksum (ProjectId={projectConeId}):\r\n{result}");
}

return;
Expand Down Expand Up @@ -154,10 +155,10 @@ private static void AddAllTo(DocumentStateChecksums documentStateChecksums, Hash
/// create checksum to corresponding object map from solution this map should contain every parts of solution
/// that can be used to re-create the solution back
/// </summary>
public static async Task<Dictionary<Checksum, object>> GetAssetMapAsync(this Solution solution, CancellationToken cancellationToken)
public static async Task<Dictionary<Checksum, object>> GetAssetMapAsync(this Solution solution, ProjectId? projectConeId, CancellationToken cancellationToken)
{
var map = new Dictionary<Checksum, object>();
await solution.AppendAssetMapAsync(map, cancellationToken).ConfigureAwait(false);
await solution.AppendAssetMapAsync(map, projectConeId, cancellationToken).ConfigureAwait(false);
return map;
}

Expand Down

0 comments on commit 8a6ff11

Please sign in to comment.