Skip to content

Commit

Permalink
Implement setTimerPeriod method (envoyproxy#528)
Browse files Browse the repository at this point in the history
* override timer method

Signed-off-by: Pengyuan Bian <[email protected]>
  • Loading branch information
bianpengyuan authored May 19, 2020
1 parent e39c788 commit 9cbb88a
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions source/extensions/common/wasm/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ void Context::initializeRoot(WasmBase* wasm, std::shared_ptr<PluginBase> plugin)
root_local_info_ = &std::static_pointer_cast<Plugin>(plugin)->local_info_;
}

WasmResult Context::setTickPeriod(std::chrono::milliseconds tick_period) {
wasm()->setTickPeriod(root_context_id_ ? root_context_id_ : id_, tick_period);
WasmResult Context::setTimerPeriod(std::chrono::milliseconds tick_period, uint32_t*) {
wasm()->setTimerPeriod(root_context_id_ ? root_context_id_ : id_, tick_period);
return WasmResult::Ok;
}

Expand Down
2 changes: 1 addition & 1 deletion source/extensions/common/wasm/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class Context : public proxy_wasm::ContextBase,

// General
WasmResult log(uint32_t level, absl::string_view message) override;
WasmResult setTimerPeriod(std::chrono::milliseconds tick_period, uint32_t* token) override;
uint64_t getCurrentTimeNanoseconds() override;
std::pair<uint32_t, absl::string_view> getStatus() override;

Expand Down Expand Up @@ -295,7 +296,6 @@ class Context : public proxy_wasm::ContextBase,
void onCloseTCP();

virtual absl::string_view getConfiguration();
virtual WasmResult setTickPeriod(std::chrono::milliseconds tick_period);
virtual void clearRouteCache() {
if (decoder_callbacks_) {
decoder_callbacks_->clearRouteCache();
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/common/wasm/wasm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ Wasm::Wasm(WasmHandleSharedPtr base_wasm_handle, Event::Dispatcher& dispatcher)
ENVOY_LOG(debug, "Thread-Local Wasm created {} now active", active_wasms);
}

void Wasm::setTickPeriod(uint32_t context_id, std::chrono::milliseconds new_tick_period) {
void Wasm::setTimerPeriod(uint32_t context_id, std::chrono::milliseconds new_tick_period) {
auto& tick_period = tick_period_[context_id];
auto& timer = timer_[context_id];
bool was_running = timer && tick_period.count() > 0;
Expand Down
2 changes: 1 addition & 1 deletion source/extensions/common/wasm/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Wasm : public WasmBase, Logger::Loggable<Logger::Id::wasm> {
Context* getRootContext(absl::string_view root_id) {
return static_cast<Context*>(WasmBase::getRootContext(root_id));
}
void setTickPeriod(uint32_t root_context_id, std::chrono::milliseconds tick_period) override;
void setTimerPeriod(uint32_t root_context_id, std::chrono::milliseconds tick_period);
virtual void tickHandler(uint32_t root_context_id);

// WasmBase
Expand Down
1 change: 0 additions & 1 deletion test/extensions/wasm/wasm_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class TestContext : public Extensions::Common::Wasm::Context {
return proxy_wasm::WasmResult::Ok;
}
MOCK_METHOD2(log_, void(spdlog::level::level_enum level, absl::string_view message));
MOCK_METHOD1(setTickPeriodMilliseconds, void(uint32_t tick_period_milliseconds));
};

class WasmTestBase {
Expand Down

0 comments on commit 9cbb88a

Please sign in to comment.