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

ignore events when cache isn't init #1896 #2019

Merged
merged 11 commits into from
Jul 15, 2021
Merged
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