Git Product home page Git Product logo

Comments (4)

bigfoot31 avatar bigfoot31 commented on August 27, 2024 1

To replicate:

  1. run go test -race
  2. replace sonic with encoding/json and then run go test -race

Versions:

  • go version go1.16.5 darwin/amd64

file: main.go

package main

import (
	"fmt"

	"github.com/bytedance/sonic"
)

func main() {
	fmt.Println("plain")
}

func ExtractJson(idx int, body interface{}) {
	j := []byte(exampleJson[idx])

	// REPLACE sonic WITH json
	err := sonic.Unmarshal(j, &body)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
}

var exampleJson1 = `{
"page_info": { "total_count": 1, "page_num": 1 },
"code": 0,
"data": [
	{
	"name": "dp-91b905d33f-5559868569-z8tvk",
	"node_ip": "10.245.11.66",
	"psm": "A.B.C",
	"containers": [
		{
			"status": "Running",
			"mem_usage_pct": 15.0,
			"name": "dp-91b905d33f",
			"cpu_usage_pct": 3.8
		},
		{
			"status": "Running",
			"mem_usage_pct": 13.0,
			"name": "dp-91b905d33f",
			"cpu_usage_pct": 2.1
		}
	]
	}
],
"error": ""
}`

var exampleJson2 = `{
	"page_info": { "total_count": 1, "page_num": 1 },
	"code": 0,
	"data": [
		{
		"name": "dp-91b905d33f-5559868569-z8tvk",
		"psm": "P.Q.R",
		"containers": [
			{
				"status": "Running",
				"mem_usage_pct": 15.0,
				"name": "dp-91b905d33f"
			},
			{
				"status": "Running",
				"name": "dp-91b905d33f",
				"cpu_usage_pct": 2.1
			}
		]
		}
	],
	"error": ""
  }`

var exampleJson = []string{exampleJson1, exampleJson2}

file: main_test.go

package main

import (
	"fmt"
	"sync"
	"testing"
)

//
//
// model definition for pod information
type podInfoResp struct {
	Data    *[]inputPodInfo `json:"data"`
	Code    *int            `json:"code"`
	Message *string         `json:"message"`
	Error   *string         `json:"error"`
}
type inputPodInfo struct {
	PSM            *string          `json:"psm"`
	NodeName       *string          `json:"name"`
	NodeIP         *string          `json:"node_ip"`
	ContainersInfo []containersInfo `json:"containers"`
}
type containersInfo struct {
	Name        *string  `json:"name"`
	Status      *string  `json:"status"`
	CPUUsagePct *float64 `json:"cpu_usage_pct"`
	MemUsagePct *float64 `json:"mem_usage_pct"`
}

func TestExtracJson(t *testing.T) {

	wg := sync.WaitGroup{}

	resultChan := make(chan podInfoResp, 2)

	wg.Add(1)
	go func() {
		defer wg.Done()
		var model podInfoResp
		ExtractJson(0, &model)
		resultChan <- model
	}()

	wg.Add(1)
	go func() {
		defer wg.Done()
		var model podInfoResp
		ExtractJson(1, &model)
		resultChan <- model
	}()

	var results []podInfoResp
	for i := 0; i < 2; i++ {
		results = append(results, <-resultChan)
	}

	close(resultChan)

	fmt.Println(*(*results[0].Data)[0].PSM)
	fmt.Println(*(*results[1].Data)[0].PSM)
}

from sonic.

chenzhuoyu avatar chenzhuoyu commented on August 27, 2024 1

Fixed in #49.

from sonic.

chenzhuoyu avatar chenzhuoyu commented on August 27, 2024

This might be a bug within the RCU map implementation. We will investigate it later.

from sonic.

AsterDY avatar AsterDY commented on August 27, 2024

@bigfoot31 Would you please give a detail UT on this issue? Although we've been aware of where the problem is but can't reproduce the same result using old codes

from sonic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.