Skip to content
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

tests: show status of the partial test-snapd-huge snap in econnreset test #5333

Merged
merged 4 commits into from
Jun 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions image/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ func (tsto *ToolingStore) DownloadSnap(name string, revision snap.Revision, opts
targetDir = pwd
}

logger.Debugf("Going to download snap %q (%s) from channel %q to %q.", name, revision, opts.Channel, opts.TargetDir)

actions := []*store.SnapAction{{
Action: "download",
Name: name,
Expand Down Expand Up @@ -248,6 +250,7 @@ func (tsto *ToolingStore) DownloadSnap(name string, revision snap.Revision, opts
logger.Debugf("not downloading, using existing file %s", targetFn)
return targetFn, snap, nil
}
logger.Debugf("File exists but has wrong hash, ignoring (here).")
}

pb := progress.MakeProgressBar()
Expand Down
7 changes: 7 additions & 0 deletions store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,7 @@ func (s *Store) Download(ctx context.Context, name string, targetPath string, do
}

if err := s.cacher.Get(downloadInfo.Sha3_384, targetPath); err == nil {
logger.Debugf("Cache hit for SHA3_384 …%.5s.", downloadInfo.Sha3_384)
return nil
}

Expand Down Expand Up @@ -1358,6 +1359,11 @@ func (s *Store) Download(ctx context.Context, name string, targetPath string, do
os.Remove(w.Name())
}
}()
if resume > 0 {
logger.Debugf("Resuming download of %q at %d.", partialPath, resume)
} else {
logger.Debugf("Starting download of %q.", partialPath)
}

authAvail, err := s.authAvailable(user)
if err != nil {
Expand Down Expand Up @@ -1391,6 +1397,7 @@ func (s *Store) Download(ctx context.Context, name string, targetPath string, do
// If hashsum is incorrect retry once
if _, ok := err.(HashError); ok {
logger.Debugf("Hashsum error on download: %v", err.Error())
logger.Debugf("Truncating and trying again from scratch.")
err = w.Truncate(0)
if err != nil {
return err
Expand Down
22 changes: 19 additions & 3 deletions tests/main/econnreset/task.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,25 @@ restore: |
# with the distro
backends: [-autopkgtest]

debug: |
echo "Partial download status"
ls -lh test-snapd-huge_* || true
echo "other dir content"
ls -lh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to dump /var/lib/snapd/cache here and reset it before the test?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, maybe? But snap download does not use that directory.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, never mind then.


execute: |
echo "Downloading a large snap in the background"
rm -f test-snapd-huge_*
su -c "/usr/bin/env SNAPD_DEBUG=1 snap download --edge test-snapd-huge 2>snap-download.log" test &
su -c "/usr/bin/env SNAPD_DEBUG=1 SNAPD_DEBUG_HTTP=3 snap download --edge test-snapd-huge 2>snap-download.log" test &

echo "Wait until the download started and downloaded more than 1 MB"
for _ in $(seq 40); do
echo "starting: $(date)"
for _ in $(seq 400); do
partial=$(find . -name 'test-snapd-huge_*.snap.partial' | head -1)
if [ -n "$partial" ] && [ "$(stat -c%s "$partial")" -gt "$(( 1024 * 1024 ))" ]; then
break
fi
sleep 1
sleep 0.1
done

if [ ! -f "$partial" ] || [ "$(stat -c%s "$partial")" -eq 0 ]; then
Expand All @@ -29,6 +36,13 @@ execute: |
exit 1
fi

if [ -n "$(find . -name 'test-snapd-huge_*.snap')" ]; then
echo "File fully downloaded before the test could act"
echo "Test broken"
echo "end: $(date)"
exit 1
fi

echo "Block the download using iptables"
iptables -I OUTPUT -m owner --uid-owner "$(id -u test)" -j REJECT -p tcp --reject-with tcp-reset

Expand All @@ -44,3 +58,5 @@ execute: |
# Note that the download will not be successful because of the nature of
# the netfilter testbed. When snap download retries the next attempt will
# end up with a "connection refused" error, something we do not retry
debug: |
cat snap-download.log