-
Notifications
You must be signed in to change notification settings - Fork 337
Minor code coverage improvements #843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
skottmckay
wants to merge
4
commits into
main
Choose a base branch
from
skottmckay/MinorCodeCoverageImprovements
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
| // | ||
| // Real-network tests for HttpDownloadFile — the generic HTTPS file downloader used by the | ||
| // execution-provider bootstrappers (WebGPU / CUDA). These are DISABLED by default because they | ||
| // require network access; the coverage run enables them via --gtest_also_run_disabled_tests. | ||
| // | ||
| // The positive case downloads the real WebGPU EP zip from the production CDN and validates the | ||
| // full binary download path (curl transport + Content-Length + progress + success). The negative | ||
| // case targets an unresolvable host so the failure path is deterministic and independent of any | ||
| // server's error-page behavior. | ||
| #include "http/http_download.h" | ||
|
|
||
| #include "logger.h" | ||
|
|
||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <atomic> | ||
| #include <filesystem> | ||
| #include <fstream> | ||
| #include <sstream> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| namespace fs = std::filesystem; | ||
| using namespace fl; | ||
|
|
||
| namespace { | ||
|
|
||
| // Production WebGPU EP package URL used for exercising large binary downloads. | ||
| constexpr const char* kWebGpuZipUrl = | ||
| "https://foundrypackages-ffhrdhbxb7gpdreh.b02.azurefd.net/webgpu_ep_0.1.0_win-x64.zip"; | ||
|
|
||
| constexpr const char* kUserAgent = "FoundryLocal"; | ||
|
|
||
| /// Captures log output so a failed download surfaces the downloader's own diagnostics. | ||
| class RecordingLogger : public ILogger { | ||
| public: | ||
| void Log(LogLevel level, std::string_view message) override { | ||
| entries.emplace_back(level, std::string(message)); | ||
| } | ||
|
|
||
| std::string Dump() const { | ||
| std::ostringstream oss; | ||
| for (const auto& [level, msg] : entries) { | ||
| oss << " [" << static_cast<int>(level) << "] " << msg << "\n"; | ||
| } | ||
| return oss.str(); | ||
| } | ||
|
|
||
| std::vector<std::pair<LogLevel, std::string>> entries; | ||
| }; | ||
|
|
||
| /// RAII temp file that removes itself on construction and destruction so each run starts clean. | ||
| class TempFile { | ||
| public: | ||
| explicit TempFile(const std::string& name) { | ||
| path_ = fs::temp_directory_path() / name; | ||
| std::error_code ec; | ||
| fs::remove(path_, ec); | ||
| } | ||
|
|
||
| ~TempFile() { | ||
| std::error_code ec; | ||
| fs::remove(path_, ec); | ||
| } | ||
|
|
||
| const fs::path& path() const { return path_; } | ||
|
|
||
| private: | ||
| fs::path path_; | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| // Downloads the real WebGPU EP zip and validates the success path end-to-end: returns | ||
| // true, writes a non-empty file, and reports a terminal 100% progress callback. | ||
| TEST(DISABLED_HttpDownload, DownloadsWebGpuZip) { | ||
| RecordingLogger logger; | ||
| TempFile dest("fl_webgpu_ep_test.zip"); | ||
|
|
||
| std::vector<float> progress; | ||
| std::atomic<bool> cancel{false}; | ||
|
|
||
| bool ok = HttpDownloadFile( | ||
| kWebGpuZipUrl, dest.path(), kUserAgent, &cancel, | ||
| [&progress](float pct) { progress.push_back(pct); }, | ||
| logger); | ||
|
|
||
| ASSERT_TRUE(ok) << "WebGPU zip download failed. Logger output:\n" | ||
| << logger.Dump(); | ||
|
|
||
| ASSERT_TRUE(fs::exists(dest.path())); | ||
| EXPECT_GT(fs::file_size(dest.path()), 0u); | ||
|
|
||
| // The final progress callback is always 100% on success. | ||
| ASSERT_FALSE(progress.empty()); | ||
| EXPECT_FLOAT_EQ(progress.back(), 100.0f); | ||
| } | ||
|
|
||
| // A transport failure (unresolvable host) returns false and leaves no output file behind. | ||
| // The reserved `.invalid` TLD (RFC 2606) never resolves, so the DNS failure is deterministic and | ||
| // fast regardless of network conditions to real hosts. | ||
| TEST(DISABLED_HttpDownload, ReturnsFalseAndWritesNoFileOnUnresolvableHost) { | ||
| RecordingLogger logger; | ||
| TempFile dest("fl_webgpu_zip_unresolvable.zip"); | ||
|
|
||
| bool ok = HttpDownloadFile("https://foundry-local-test.invalid/webgpu_ep_0.1.0_win-x64.zip", dest.path(), | ||
| kUserAgent, /*cancel_flag=*/nullptr, /*progress_cb=*/{}, logger); | ||
|
|
||
| EXPECT_FALSE(ok); | ||
| EXPECT_FALSE(fs::exists(dest.path())); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will consolidate this with changes in #851 depending on which PR goes in first.