Skip to content

Commit

Permalink
remove invalid tests
Browse files Browse the repository at this point in the history
move functions out of utils
address review comments
  • Loading branch information
nikooo777 committed Jul 17, 2018
1 parent dfa3bb1 commit 906c909
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 107 deletions.
37 changes: 0 additions & 37 deletions cmd/selfsync_test.go

This file was deleted.

18 changes: 0 additions & 18 deletions util/disk_space.go

This file was deleted.

21 changes: 0 additions & 21 deletions util/disk_space_test.go

This file was deleted.

20 changes: 0 additions & 20 deletions util/slack_test.go

This file was deleted.

3 changes: 2 additions & 1 deletion util/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ func InSlice(str string, values []string) bool {
return false
}

func InSliceContains(fullString string, candidates []string) bool {
// ContainedInSlice returns true if fullstring is contained within any element of the candidates slice. False otherwise
func ContainedInSlice(fullString string, candidates []string) bool {
for _, v := range candidates {
if strings.Contains(fullString, v) {
return true
Expand Down
21 changes: 19 additions & 2 deletions ytsync/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

"time"

"syscall"

"github.com/lbryio/lbry.go/errors"
"github.com/lbryio/lbry.go/null"
"github.com/lbryio/lbry.go/util"
Expand Down Expand Up @@ -214,7 +216,7 @@ func (s SyncManager) Start() error {
"NotEnoughFunds",
"no space left on device",
}
if util.InSliceContains(err.Error(), fatalErrors) {
if util.ContainedInSlice(err.Error(), fatalErrors) {
return errors.Prefix("@Nikooo777 this requires manual intervention! Exiting...", err)
}
util.SendInfoToSlack("A non fatal error was reported by the sync process. %s\nContinuing...", err.Error())
Expand Down Expand Up @@ -243,7 +245,7 @@ func (s SyncManager) checkUsedSpace() error {
if err != nil {
return err
}
usedPctile, err := util.GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/")
usedPctile, err := GetUsedSpace(usr.HomeDir + "/.lbrynet/blobfiles/")
if err != nil {
return err
}
Expand All @@ -253,3 +255,18 @@ func (s SyncManager) checkUsedSpace() error {
util.SendInfoToSlack("disk usage: %.1f%%", usedPctile*100)
return nil
}

// GetUsedSpace returns a value between 0 and 1, with 0 being completely empty and 1 being full, for the disk that holds the provided path
func GetUsedSpace(path string) (float32, error) {
var stat syscall.Statfs_t
err := syscall.Statfs(path, &stat)
if err != nil {
return 0, err
}
// Available blocks * size per block = available space in bytes
all := stat.Blocks * uint64(stat.Bsize)
free := stat.Bfree * uint64(stat.Bsize)
used := all - free

return float32(used) / float32(all), nil
}
2 changes: 1 addition & 1 deletion ytsync/sources/youtubeVideo.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (v YoutubeVideo) delete() error {
videoPath := v.getFilename()
err := os.Remove(videoPath)
if err != nil {
log.Debugln(errors.Prefix("delete error", err))
log.Errorln(errors.Prefix("delete error", err))
return err
}
log.Debugln(v.id + " deleted from disk (" + videoPath + ")")
Expand Down
11 changes: 4 additions & 7 deletions ytsync/ytsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (s *Sync) FullCycle() (e error) {
noFailConditions := []string{
"this youtube channel is being managed by another server",
}
if util.InSliceContains(e.Error(), noFailConditions) {
if util.ContainedInSlice(e.Error(), noFailConditions) {
return
}
err := s.Manager.setChannelSyncStatus(s.YoutubeChannelID, StatusFailed)
Expand Down Expand Up @@ -219,7 +219,7 @@ func (s *Sync) doSync() error {

err = s.walletSetup()
if err != nil {
return errors.Err("Initial wallet setup failed! Manual Intervention is required. Reason: %v", err)
return errors.Prefix("Initial wallet setup failed! Manual Intervention is required.", err)
}

if s.StopOnError {
Expand Down Expand Up @@ -281,7 +281,7 @@ func (s *Sync) startWorker(workerNum int) {
"NotEnoughFunds",
"Cannot publish using channel",
}
if util.InSliceContains(err.Error(), fatalErrors) || s.StopOnError {
if util.ContainedInSlice(err.Error(), fatalErrors) || s.StopOnError {
s.grp.Stop()
} else if s.MaxTries > 1 {
errorsNoRetry := []string{
Expand All @@ -296,7 +296,7 @@ func (s *Sync) startWorker(workerNum int) {
"Client.Timeout exceeded while awaiting headers)",
"video is bigger than 2GB, skipping for now",
}
if util.InSliceContains(err.Error(), errorsNoRetry) {
if util.ContainedInSlice(err.Error(), errorsNoRetry) {
log.Println("This error should not be retried at all")
} else if tryCount < s.MaxTries {
if strings.Contains(err.Error(), "txn-mempool-conflict") ||
Expand Down Expand Up @@ -369,9 +369,6 @@ func (s *Sync) enqueueYoutubeVideos() error {
}

for _, item := range playlistResponse.Items {
// todo: there's thumbnail info here. why did we need lambda???
// because when videos are taken down from youtube, the thumb is gone too

// normally we'd send the video into the channel here, but youtube api doesn't have sorting
// so we have to get ALL the videos, then sort them, then send them in
videos = append(videos, sources.NewYoutubeVideo(s.videoDirectory, item.Snippet))
Expand Down

0 comments on commit 906c909

Please sign in to comment.