From 9805a2b57a95f25f4f200c6920ced01dc8d63bf0 Mon Sep 17 00:00:00 2001 From: Srikanth Date: Thu, 15 Jul 2021 07:12:23 +0530 Subject: [PATCH] ignore events when cache isn't init #1896 (#2019) * ignore events when cache isn't init #1896 Signed-off-by: sriv * add filewatcher after cache init Signed-off-by: sriv * bump version -> 1.3.3 Signed-off-by: sriv Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- api/infoGatherer/specDetails.go | 27 ++++++++++++++++++--------- version/version.go | 2 +- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/api/infoGatherer/specDetails.go b/api/infoGatherer/specDetails.go index b43336cce..285f04ce0 100644 --- a/api/infoGatherer/specDetails.go +++ b/api/infoGatherer/specDetails.go @@ -73,15 +73,15 @@ func NewSpecInfoGatherer(conceptDictionary *gauge.ConceptDictionary) *SpecInfoGa // Init initializes all the SpecInfoGatherer caches func (s *SpecInfoGatherer) Init() { - go s.watchForFileChanges() - s.waitGroup.Wait() - // Concepts parsed first because we need to create a concept dictionary that spec parsing can use s.initConceptsCache() s.initSpecsCache() s.initStepsCache() s.initParamsCache() s.initTagsCache() + + go s.watchForFileChanges() + s.waitGroup.Wait() } func (s *SpecInfoGatherer) initTagsCache() { s.tagsCache.mutex.Lock() @@ -224,10 +224,16 @@ func removeDuplicateTags(tags []string) []string { } func (s *SpecInfoGatherer) addToSpecsCache(key string, value *SpecDetail) { + if s.specsCache.specDetails == nil { + return + } s.specsCache.specDetails[key] = value } func (s *SpecInfoGatherer) addToConceptsCache(key string, value *gauge.Concept) { + if s.conceptsCache.concepts == nil { + return + } if s.conceptsCache.concepts[key] == nil { s.conceptsCache.concepts[key] = make([]*gauge.Concept, 0) } @@ -243,6 +249,9 @@ func (s *SpecInfoGatherer) deleteFromConceptDictionary(file string) { } func (s *SpecInfoGatherer) addToStepsCache(fileName string, allSteps []*gauge.Step) { + if s.stepsCache.steps == nil { + return + } s.stepsCache.steps[fileName] = allSteps } @@ -304,7 +313,7 @@ func (s *SpecInfoGatherer) getStepsFromCachedConcepts() map[string][]*gauge.Step } func (s *SpecInfoGatherer) OnSpecFileModify(file string) { - logger.Infof(false, "Spec file added / modified: %s", file) + logger.Debugf(false, "Spec file added / modified: %s", file) details := s.getParsedSpecs([]string{file}) s.specsCache.mutex.Lock() @@ -330,7 +339,7 @@ func (s *SpecInfoGatherer) OnConceptFileModify(file string) { s.conceptsCache.mutex.Lock() defer s.conceptsCache.mutex.Unlock() - logger.Infof(false, "Concept file added / modified: %s", file) + logger.Debugf(false, "Concept file added / modified: %s", file) s.deleteFromConceptDictionary(file) concepts, parseErrors, err := parser.AddConcepts([]string{file}, s.conceptDictionary) if err != nil { @@ -356,7 +365,7 @@ func (s *SpecInfoGatherer) OnConceptFileModify(file string) { } func (s *SpecInfoGatherer) onSpecFileRemove(file string) { - logger.Infof(false, "Spec file removed: %s", file) + logger.Debugf(false, "Spec file removed: %s", file) s.specsCache.mutex.Lock() defer s.specsCache.mutex.Unlock() delete(s.specsCache.specDetails, file) @@ -369,7 +378,7 @@ func (s *SpecInfoGatherer) removeStepsFromCache(fileName string) { } func (s *SpecInfoGatherer) onConceptFileRemove(file string) { - logger.Infof(false, "Concept file removed: %s", file) + logger.Debugf(false, "Concept file removed: %s", file) s.conceptsCache.mutex.Lock() defer s.conceptsCache.mutex.Unlock() s.deleteFromConceptDictionary(file) @@ -596,14 +605,14 @@ func addDirToFileWatcher(watcher *fsnotify.Watcher, dir string) { if err != nil { logger.Errorf(false, "Unable to add directory %v to file watcher: %s", dir, err.Error()) } else { - logger.Infof(false, "Watching directory: %s", dir) + logger.Debugf(false, "Watching directory: %s", dir) files, _ := ioutil.ReadDir(dir) logger.Debugf(false, "Found %d files", len(files)) } } func removeWatcherOn(watcher *fsnotify.Watcher, path string) { - logger.Infof(false, "Removing watcher on : %s", path) + logger.Debugf(false, "Removing watcher on : %s", path) err := watcher.Remove(path) if err != nil { logger.Errorf(false, "Unable to remove watcher on: %s. %s", path, err.Error()) diff --git a/version/version.go b/version/version.go index 0840079ff..0d8c59f19 100644 --- a/version/version.go +++ b/version/version.go @@ -14,7 +14,7 @@ import ( ) // CurrentGaugeVersion represents the current version of Gauge -var CurrentGaugeVersion = &Version{1, 3, 2} +var CurrentGaugeVersion = &Version{1, 3, 3} // BuildMetadata represents build information of current release (e.g, nightly build information) var BuildMetadata = ""