Skip to content

Commit

Permalink
ignore events when cache isn't init #1896 (#2019)
Browse files Browse the repository at this point in the history
* ignore events when cache isn't init #1896

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* add filewatcher after cache init

Signed-off-by: sriv <srikanth.ddit@gmail.com>

* bump version -> 1.3.3

Signed-off-by: sriv <srikanth.ddit@gmail.com>

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
sriv and github-actions[bot] authored Jul 15, 2021
1 parent 32c3dd5 commit 9805a2b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
27 changes: 18 additions & 9 deletions api/infoGatherer/specDetails.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}

Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down

0 comments on commit 9805a2b

Please sign in to comment.