Skip to content

Commit

Permalink
improved tracing of package upload verification mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierdecoster committed Jun 30, 2015
1 parent 48d61b4 commit 065f248
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions tests/Local.testsettings
Expand Up @@ -2,9 +2,8 @@
<TestSettings name="Local" id="62f583f0-2eca-4773-bed0-474a13faad76" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<Description>These are default test settings for a local test run.</Description>
<Deployment userDeploymentRoot="." useDefaultDeploymentRoot="false">
<DeploymentItem filename=".nuget\NuGet.Config" />
<DeploymentItem filename=".nuget\NuGet.exe" />
<DeploymentItem filename=".nuget\NuGet.targets" />
<DeploymentItem filename=".nuget\NuGet.Config" />
</Deployment>
<NamingScheme baseName="TestResults" appendTimeStamp="false" useDefault="false" />
<Execution>
Expand All @@ -28,4 +27,5 @@
<AgentRule name="LocalMachineDefaultRole">
</AgentRule>
</Execution>
<Properties />
</TestSettings>
46 changes: 29 additions & 17 deletions tests/NuGetGallery.FunctionalTests.Helpers/ClientSDKHelper.cs
Expand Up @@ -44,19 +44,19 @@ public static int GetVersionCount(string packageId,bool allowPreRelease=true)
return packages.Count;
}
else
return 0;
return 0;
}
/// <summary>
/// Returns the download count of the given package as a formatted string as it would appear in the gallery UI.
/// </summary>
/// <param name="packageId"></param>
/// <returns></returns>
public static string GetFormattedDownLoadStatistics(string packageId)
{
{
string formattedCount = GetDownLoadStatistics(packageId).ToString("N1", CultureInfo.InvariantCulture);
if (formattedCount.EndsWith(".0"))
formattedCount = formattedCount.Remove(formattedCount.Length - 2);
return formattedCount;
return formattedCount;
}

/// <summary>
Expand Down Expand Up @@ -93,7 +93,7 @@ public static int GetPackageCountForSearchTerm(string searchQuery)
List<IPackage> packages;
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(sourceUrl) as IPackageRepository;
IPackageRepository serviceRepo = repo as IPackageRepository;

if(serviceRepo != null)
{
packages = serviceRepo.Search(searchQuery,false).ToList();
Expand Down Expand Up @@ -121,7 +121,7 @@ public static string GetPackageIdFromNupkgFile(string filePath)
{
Console.WriteLine(" Exception thrown while trying to create zippackage for :{0}. Message {1}", filePath, e.Message);
return null;
}
}
}

/// <summary>
Expand All @@ -136,7 +136,7 @@ public static bool IsPackageVersionUnListed(string packageId,string version)
if (package != null)
return !package.Listed;
else
return false;
return false;
}

/// <summary>
Expand All @@ -158,33 +158,45 @@ public static bool CheckIfPackageExistsInSource(string packageId, string sourceU
/// <returns></returns>
public static bool CheckIfPackageVersionExistsInSource(string packageId, string version, string sourceUrl)
{
bool found = false;
// A new way to check if packages exist in source. The logic above often gives timeout errors randomly.
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(sourceUrl) as IPackageRepository;
var found = false;
var repo = PackageRepositoryFactory.Default.CreateRepository(sourceUrl);
SemanticVersion semVersion;
bool success = SemanticVersion.TryParse(version, out semVersion);
var success = SemanticVersion.TryParse(version, out semVersion);
const int interval = 60;

if (success)
{
try
{
for (int i = 0; ((i < 5) && (!found)); i++)
Console.WriteLine("Starting package verification checks (5 attempts, interval 60 seconds).");
Console.WriteLine();
for (var i = 0; ((i < 5) && (!found)); i++)
{
// Wait for the search service to kick in, so that the package can be found via FindPackage(packageId, SemanticVersion)
Thread.Sleep(60 * 1000);
Console.Write("[verification attempt {0}]: Waiting {1} seconds before next check...", i, interval);
Thread.Sleep(interval * 1000);

Console.Write("[verification attempt {0}]: Checking if package {1} with version {2} exists in source {3}... ", i, packageId, version, sourceUrl);
IPackage package = repo.FindPackage(packageId, semVersion);
found = (package != null);
if (found)
{
Console.Write("Found!");
Console.WriteLine();
}
else
{
Console.Write("NOT found!");
Console.WriteLine();
}
}
}
catch (Exception ex)
{
Console.WriteLine("Exception thrown while checking the existence of package {0} with version (1}:\r\n {2}", packageId, version, ex.Message);
Console.WriteLine("Exception thrown while checking the existence of package {0} with version {1}:\r\n {2}", packageId, version, ex.Message);
}
}

if (found)
{
Console.WriteLine("Found package {0} with version {1} in sourceUrl of {2}", packageId, version, sourceUrl);
}
return found;
}

Expand Down
Expand Up @@ -26,7 +26,10 @@ public async Task FindPackagesByIdTest()
{
string packageId = "TestV2FeedFindPackagesById" + "." + DateTime.UtcNow.Ticks;

TestContext.WriteLine("Uploading package '{0}'", packageId);
await AssertAndValidationHelper.UploadNewPackageAndVerify(packageId).ConfigureAwait(false);
TestContext.WriteLine("Uploaded package '{0}'", packageId);

await AssertAndValidationHelper.UploadNewPackageAndVerify(packageId, "2.0.0").ConfigureAwait(false);

string url = UrlHelper.V2FeedRootUrl + @"/FindPackagesById()?id='" + packageId + "'";
Expand Down

0 comments on commit 065f248

Please sign in to comment.