Skip to content

Commit

Permalink
feat: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyi-gronk committed May 26, 2024
1 parent 125ba1b commit dc1a92d
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions packages/dubbo-observable/src/qps-counter.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { QpsCounter } from "./qps-counter.js";

describe("QpsCounter Error", () => {
console.log("");
})
describe("QpsCounter", function () {
let qpsCounter = new QpsCounter();

beforeEach(function () {
jasmine.clock().install();
jasmine.clock().mockDate(new Date());
qpsCounter = new QpsCounter();
});

afterEach(function () {
jasmine.clock().uninstall();
qpsCounter.stop();
});

it("should initialize counter correctly", function () {
expect(qpsCounter).toBeDefined();
expect(qpsCounter.getQps()).toBe(0);
});

it("should increment the counter correctly", function () {
qpsCounter.increment();
qpsCounter.increment();
qpsCounter.increment();
expect(qpsCounter.getQps()).toBe(0);

jasmine.clock().tick(1000);

expect(qpsCounter.getQps()).toBe(3);
});
});

0 comments on commit dc1a92d

Please sign in to comment.