Skip to content

Commit bf0b5a0

Browse files
Test showing this idea is completely broken
Test fails with: Expected: 6959 But was: 6958 So we should abandon this... 😢
1 parent 091da6d commit bf0b5a0

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed
Binary file not shown.

src/Java.Interop.Tools.JavaCallableWrappers/Test/Java.Interop.Tools.JavaCallableWrappers-Tests.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
<HintPath>..\..\..\packages\NUnit.3.7.1\lib\net45\nunit.framework.dll</HintPath>
3535
</Reference>
3636
<Reference Include="System" />
37+
<Reference Include="System.IO.Compression" />
38+
<Reference Include="System.IO.Compression.FileSystem" />
3739
</ItemGroup>
3840
<ItemGroup>
3941
<Compile Include="Java.Interop.Tools.JavaCallableWrappers\JavaCallableWrapperGeneratorTests.cs" />
@@ -47,6 +49,9 @@
4749
<Compile Include="Android.Content\ContentProviderAttribute.cs" />
4850
</ItemGroup>
4951
<ItemGroup>
52+
<Content Include="Data\Assemblies.zip">
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</Content>
5055
<None Include="packages.config" />
5156
</ItemGroup>
5257
<ItemGroup>

src/Java.Interop.Tools.JavaCallableWrappers/Test/Java.Interop.Tools.JavaCallableWrappers/JavaCallableWrapperGeneratorTests.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
24
using System.IO;
5+
using System.IO.Compression;
36
using System.Linq;
47
using System.Threading.Tasks;
58

@@ -13,6 +16,7 @@
1316
using Java.Interop.Tools.TypeNameMappings;
1417

1518
using Xamarin.Android.ToolsTests;
19+
using Java.Interop.Tools.Cecil;
1620

1721
namespace Java.Interop.Tools.JavaCallableWrappersTests
1822
{
@@ -491,6 +495,66 @@ public void monodroidClearReferences ()
491495
";
492496
Assert.AreEqual (expected, actual);
493497
}
498+
499+
[Test, Repeat (10)]
500+
public void GenerateInParallel ()
501+
{
502+
var zipPath = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location), "Data", "assemblies.zip");
503+
var dest = Path.Combine (Path.GetTempPath (), Path.GetRandomFileName ());
504+
try {
505+
Directory.CreateDirectory (dest);
506+
var assemblies = new List<string> ();
507+
508+
using (var zip = ZipFile.OpenRead (zipPath)) {
509+
foreach (var entry in zip.Entries) {
510+
var path = Path.Combine (dest, entry.FullName);
511+
assemblies.Add (path);
512+
513+
using (var fs = File.Create (path))
514+
using (var zs = entry.Open ()) {
515+
zs.CopyTo (fs);
516+
}
517+
}
518+
}
519+
520+
Action<TraceLevel, string> logger = (l, m) => {
521+
TestContext.WriteLine ($"{l} {m}");
522+
};
523+
524+
using (var res = new DirectoryAssemblyResolver (logger, loadDebugSymbols: false)) {
525+
res.SearchDirectories.Add (dest);
526+
foreach (var assembly in assemblies) {
527+
res.Load (assembly);
528+
}
529+
530+
var scanner = new JavaTypeScanner (logger);
531+
var sw = new Stopwatch ();
532+
533+
sw.Reset ();
534+
sw.Start ();
535+
var parallelTypes = scanner.GetJavaTypesInParallel (assemblies, res);
536+
sw.Stop ();
537+
TestContext.WriteLine ($"Parallel took: {sw.Elapsed}");
538+
539+
sw.Reset ();
540+
sw.Start ();
541+
var types = scanner.GetJavaTypes (assemblies, res);
542+
sw.Stop ();
543+
TestContext.WriteLine ($"Non parallel took: {sw.Elapsed}");
544+
545+
types.Sort ((a, b) => a.FullName.CompareTo (b.FullName));
546+
parallelTypes.Sort ((a, b) => a.FullName.CompareTo (b.FullName));
547+
548+
Assert.AreEqual (types.Count, parallelTypes.Count);
549+
for (int i = 0; i < types.Count; i++) {
550+
Assert.AreEqual (types [i].FullName, parallelTypes [i].FullName);
551+
}
552+
}
553+
554+
} finally {
555+
Directory.Delete (dest, true);
556+
}
557+
}
494558
}
495559
}
496560

0 commit comments

Comments
 (0)