diff --git a/cypress/plugins/tasks.js b/cypress/plugins/tasks.js index c3768cdacd..13f0839ff0 100644 --- a/cypress/plugins/tasks.js +++ b/cypress/plugins/tasks.js @@ -77,18 +77,10 @@ const sqlTask = on => { }, dropAndSeedDatabase: async () => { const exec = util.promisify(childProcess.exec) - - // Restore SQL data - await exec('tools/bin/mage dev:sqlRestore', { cwd: '..' }) - - // Flush Redis database - try { - await exec('tools/bin/mage dev:redisFlush', { cwd: '..' }) - } catch (e) { - // eslint-disable-next-line no-console - console.log('Error flushing Redis:', e) - } - + await Promise.all([ + exec('tools/bin/mage dev:sqlRestore', { cwd: '..' }), + exec('tools/bin/mage -v dev:redisFlush', { cwd: '..' }), + ]) return null }, }) diff --git a/tools/mage/dev.go b/tools/mage/dev.go index cd0e903cb3..7158329622 100644 --- a/tools/mage/dev.go +++ b/tools/mage/dev.go @@ -135,21 +135,39 @@ func (Dev) SQLRestore() error { ) } -// RedisFlush deletes all keys from redis. +// RedisFlush deletes all keys from redis except specific task queues. func (Dev) RedisFlush() error { if mg.Verbose() { - fmt.Println("Deleting all keys from redis") + fmt.Println("Deleting keys from redis (preserving task queues)") } keys, err := sh.Output("docker", dockerComposeFlags("exec", "-T", "redis", "redis-cli", "keys", "ttn:v3:*")...) if err != nil { return err } + ks := strings.Split(keys, "\n") if len(ks) == 0 { return nil } - flags := dockerComposeFlags(append([]string{"exec", "-T", "redis", "redis-cli", "del"}, ks...)...) + + // Delete all keys except preserved ones + baseArgs := []string{"exec", "-T", "redis", "redis-cli", "del"} + keysToDelete := make([]string, 0, len(ks)) + + for _, k := range ks { + if k != "ttn:v3:ns:tasks:downlink:ready" && + k != "ttn:v3:ns:tasks:downlink:input" && + k != "ttn:v3:ns:application-uplinks:uplinks" { + keysToDelete = append(keysToDelete, k) + } + } + // No keys to delete + if len(keysToDelete) == len(baseArgs) { + return nil + } + + flags := dockerComposeFlags(append(baseArgs, keysToDelete...)...) _, err = sh.Exec(nil, nil, os.Stderr, "docker", flags...) return err }