MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / TestDatabaseRecycle

Function TestDatabaseRecycle

worker/db_test.go:434–521  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

432}
433
434func TestDatabaseRecycle(t *testing.T) {
435 defer leaktest.Check(t)()
436 defer kms.ClosePublicKeyStore()
437
438 // test init/shutdown/destroy
439 // test goroutine status
440 Convey("test init destroy", t, func() {
441 var err error
442 var server *rpc.Server
443 var cleanup func()
444 cleanup, server, err = initNode()
445 So(err, ShouldBeNil)
446
447 defer cleanup()
448
449 var rootDir string
450 rootDir, err = ioutil.TempDir("", "db_test_")
451 So(err, ShouldBeNil)
452
453 // create mux service
454 kayakMuxService, err := NewDBKayakMuxService("DBKayak", server)
455 So(err, ShouldBeNil)
456
457 chainMuxService, err := sqlchain.NewMuxService("sqlchain", server)
458 So(err, ShouldBeNil)
459
460 // create peers
461 var peers *proto.Peers
462 peers, err = getPeers(1)
463 So(err, ShouldBeNil)
464
465 // create file
466 cfg := &DBConfig{
467 DatabaseID: "00000bef611d346c0cbe1beaa76e7f0ed705a194fdf9ac3a248ec70e9c198bf9",
468 DataDir: rootDir,
469 KayakMux: kayakMuxService,
470 ChainMux: chainMuxService,
471 MaxWriteTimeGap: time.Duration(5 * time.Second),
472 UpdateBlockCount: 2,
473 }
474
475 // create genesis block
476 var block *types.Block
477 block, err = types.CreateRandomBlock(rootHash, true)
478 So(err, ShouldBeNil)
479
480 // create database
481 var db *Database
482 db, err = NewDatabase(cfg, peers, block)
483 So(err, ShouldBeNil)
484
485 // do some query
486 var writeQuery *types.Request
487 var res *types.Response
488 writeQuery, err = buildQuery(types.WriteQuery, 1, 1, []string{
489 "create table test (test int)",
490 "insert into test values(1)",
491 })

Callers

nothing calls this directly

Calls 12

QueryMethod · 0.95
DestroyMethod · 0.95
ClosePublicKeyStoreFunction · 0.92
NewMuxServiceFunction · 0.92
CreateRandomBlockFunction · 0.92
NewDBKayakMuxServiceFunction · 0.85
StatMethod · 0.80
initNodeFunction · 0.70
getPeersFunction · 0.70
NewDatabaseFunction · 0.70
buildQueryFunction · 0.70
CheckMethod · 0.65

Tested by

no test coverage detected