Skip to content

Commit

Permalink
Merge branch 'master' into support_hb_metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot[bot] authored Jul 29, 2024
2 parents 1dfcbfc + c53f1d5 commit b0c2cbe
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions server/api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,23 @@ func (h *confHandler) SetConfig(w http.ResponseWriter, r *http.Request) {
return
}

if ttlSec := r.URL.Query().Get("ttlSecond"); ttlSec != "" {
ttls, err := strconv.Atoi(ttlSec)
if ttlString := r.URL.Query().Get("ttlSecond"); ttlString != "" {
ttlSec, err := strconv.Atoi(ttlString)
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
// if ttlSecond defined, we will apply if to temp configuration.
err = h.svr.SaveTTLConfig(conf, time.Duration(ttls)*time.Second)
err = h.svr.SaveTTLConfig(conf, time.Duration(ttlSec)*time.Second)
if err != nil {
h.rd.JSON(w, http.StatusBadRequest, err.Error())
return
}
h.rd.JSON(w, http.StatusOK, "The config is updated.")
if ttlSec == 0 {
h.rd.JSON(w, http.StatusOK, "The ttl config is deleted.")
} else {
h.rd.JSON(w, http.StatusOK, "The ttl config is updated.")
}
return
}

Expand Down
6 changes: 4 additions & 2 deletions tests/server/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,10 +530,12 @@ func (suite *configTestSuite) checkConfigTTL(cluster *tests.TestCluster) {
assertTTLConfig(re, cluster, false)

// test cleaning up
err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 5), postData, tu.StatusOK(re))
err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 5), postData,
tu.StatusOK(re), tu.StringEqual(re, "\"The ttl config is updated.\"\n"))
re.NoError(err)
assertTTLConfig(re, cluster, true)
err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 0), postData, tu.StatusOK(re))
err = tu.CheckPostJSON(tests.TestDialClient, createTTLUrl(urlPrefix, 0), postData,
tu.StatusOK(re), tu.StatusOK(re), tu.StringEqual(re, "\"The ttl config is deleted.\"\n"))
re.NoError(err)
assertTTLConfig(re, cluster, false)

Expand Down

0 comments on commit b0c2cbe

Please sign in to comment.