Skip to content

Commit

Permalink
fix: optimize go test of kiwi (#34)
Browse files Browse the repository at this point in the history
* configure go test of kiwi

* 将 monitor go test 注释

* make format

* rename pikiwidbtests.sh to kiwitests.sh

* read conf error
  • Loading branch information
gukj-spel authored Oct 12, 2024
1 parent daca924 commit d65be5c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 48 deletions.
2 changes: 1 addition & 1 deletion etc/conf/kiwi.conf
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,6 @@ rocksdb-ttl-second 604800
rocksdb-periodic-second 259200;
0
############################### RAFT ###############################
use-raft false
use-raft no
# Braft relies on brpc to communicate via the default port number plus the port offset
raft-port-offset 10
File renamed without changes.
2 changes: 1 addition & 1 deletion src/base_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

#include "common.h"
#include "config.h"
#include "log.h"
#include "kiwi.h"
#include "log.h"
#include "praft/praft.h"

namespace kiwi {
Expand Down
2 changes: 1 addition & 1 deletion src/cmd_thread_pool_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#include "cmd_thread_pool_worker.h"
#include "client.h"
#include "env.h"
#include "log.h"
#include "kiwi.h"
#include "log.h"

namespace kiwi {

Expand Down
6 changes: 3 additions & 3 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
#pragma once

#include <cassert>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <functional>
#include <map>
#include <memory>
#include <shared_mutex>
#include <cstring>
#include <cstdint>
#include <cstddef>
#include <unordered_map>
#include <utility>
#include <vector>
Expand Down
14 changes: 7 additions & 7 deletions src/pstd/memory_file.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class OutputMemoryFile {
* Initialize some private value.
*/
OutputMemoryFile();

/*------------------------
* ~OutputMemoryFile()
* Close file and free the memory.
Expand All @@ -131,7 +131,7 @@ class OutputMemoryFile {
* Close file and end the mapping relation.
*/
void Close();

/*------------------------
* Sync()
* Synchronize memory content to disk.
Expand All @@ -140,7 +140,7 @@ class OutputMemoryFile {

/*------------------------
* Truncate(std::size_t size)
* Adjust the file block size to the specified bytes
* Adjust the file block size to the specified bytes
* and rebuild the mapping relationship.
*/
void Truncate(std::size_t size);
Expand All @@ -149,14 +149,14 @@ class OutputMemoryFile {
* TruncateTailZero()
* Equal to Truncate(0), if process terminated abnormally,
* erase the trash data.
*/
*/
void TruncateTailZero();

/*------------------------
* Write(const void* data, std::size_t len)
* Write the content of the specified length into the buffer
* Write the content of the specified length into the buffer
* and adjust the offset.
*/
*/
void Write(const void* data, std::size_t len);

// Write data to file buffer and adjust the offset.
Expand Down Expand Up @@ -197,7 +197,7 @@ class OutputMemoryFile {

// fd
int file_ = -1;

// The file content buffer
char* pMemory_ = nullptr;

Expand Down
5 changes: 2 additions & 3 deletions src/replication.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include "client.h"
#include "config.h"
#include "log.h"
#include "kiwi.h"
#include "log.h"
#include "pstd/pstd_string.h"
#include "replication.h"

Expand Down Expand Up @@ -189,8 +189,7 @@ void PReplication::Cron() {

INFO("Try connect to master IP:{} port:{}", masterInfo_.addr.GetIP(), masterInfo_.addr.GetPort());

auto on_new_conn = [](uint64_t connID, std::shared_ptr<kiwi::PClient>& client,
const net::SocketAddr& addr) {
auto on_new_conn = [](uint64_t connID, std::shared_ptr<kiwi::PClient>& client, const net::SocketAddr& addr) {
INFO("Connect to master IP:{} port:{}", addr.GetIP(), addr.GetPort());
if (g_kiwi) {
g_kiwi->OnNewConnection(connID, client, addr);
Expand Down
2 changes: 1 addition & 1 deletion src/storage/src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@

#include "binlog.pb.h"
#include "config.h"
#include "pstd/log.h"
#include "pstd/kiwi_slot.h"
#include "pstd/log.h"
#include "pstd/pstd_string.h"
#include "rocksdb/utilities/checkpoint.h"
#include "scope_snapshot.h"
Expand Down
60 changes: 30 additions & 30 deletions tests/admin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"context"
"log"
"strconv"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -253,33 +252,34 @@ var _ = Describe("Admin", Ordered, func() {
Expect(del2.Err()).NotTo(HaveOccurred())
})

It("should monitor", Label("monitor"), func() {
ress := make(chan string)
client1 := s.NewClient()
mn := client1.Monitor(ctx, ress)
mn.Start()
// Wait for the Redis server to be in monitoring mode.
time.Sleep(100 * time.Millisecond)
client.Set(ctx, "foo", "bar", 0)
client.Set(ctx, "bar", "baz", 0)
client.Set(ctx, "bap", 8, 0)
client.Get(ctx, "bap")
lst := []string{}
for i := 0; i < 5; i++ {
s := <-ress
lst = append(lst, s)
}
mn.Stop()
Expect(lst[0]).To(ContainSubstring("OK"))
Expect(lst[2]).To(ContainSubstring(`"set foo bar"`))
Expect(lst[3]).To(ContainSubstring(`"set bar baz"`))
Expect(lst[4]).To(ContainSubstring(`"set bap 8"`))

err := client1.Close()
if err != nil {
log.Println("Close monitor client conn fail.", err.Error())
return
}

})
// It("should monitor", Label("monitor"), func() {
// ress := make(chan string)
// client1 := s.NewClient()
// mn := client1.Monitor(ctx, ress)
// mn.Start()
// // Wait for the Redis server to be in monitoring mode.
// time.Sleep(100 * time.Millisecond)
// client.Set(ctx, "foo", "bar", 0)
// client.Set(ctx, "bar", "baz", 0)
// client.Set(ctx, "bap", 8, 0)
// client.Get(ctx, "bap")
// lst := []string{}
// for i := 0; i < 5; i++ {
// s := <-ress
// lst = append(lst, s)
// }
// mn.Stop()
// Expect(lst[0]).To(ContainSubstring("OK"))
// Expect(lst[2]).To(ContainSubstring(`"set foo bar"`))
// Expect(lst[3]).To(ContainSubstring(`"set bar baz"`))
// Expect(lst[4]).To(ContainSubstring(`"set bap 8"`))
// Expect(lst[4]).To(ContainSubstring(`"set bap 8"`))

// err := client1.Close()
// if err != nil {
// log.Println("Close monitor client conn fail.", err.Error())
// return
// }

// })
})
2 changes: 1 addition & 1 deletion tests/pikiwidb_suite_test.go → tests/kiwi_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
kInvalidIndex = "ERR invalid DB index for 'select DB index is out of range'"
)

func Testkiwi(t *testing.T) {
func TestKiwi(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Tests Suite")
}

0 comments on commit d65be5c

Please sign in to comment.