Home / Function/ Test_Session_Concurrency() — fiber Function Reference

Test_Session_Concurrency() — fiber Function Reference

Architecture documentation for the Test_Session_Concurrency() function in session_test.go from the fiber codebase.

Entity Profile

Dependency Diagram

graph TD
  0983f50c_611b_d392_66d2_eaa1c910908b["Test_Session_Concurrency()"]
  397e6e82_749b_4ef2_9365_02be671c59f7["session_test.go"]
  0983f50c_611b_d392_66d2_eaa1c910908b -->|defined in| 397e6e82_749b_4ef2_9365_02be671c59f7
  style 0983f50c_611b_d392_66d2_eaa1c910908b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

middleware/session/session_test.go lines 1425–1527

func Test_Session_Concurrency(t *testing.T) {
	app := fiber.New()
	store := NewStore()

	var wg sync.WaitGroup
	errChan := make(chan error, 10) // Buffered channel to collect errors
	const numGoroutines = 10        // Number of concurrent goroutines to test

	// Start numGoroutines goroutines
	for range numGoroutines {
		wg.Go(func() {
			localCtx := app.AcquireCtx(&fasthttp.RequestCtx{})

			sess, err := store.getSession(localCtx)
			if err != nil {
				errChan <- err
				return
			}

			// Set a value
			sess.Set("name", "john")

			// get the session id
			id := sess.ID()

			// Check if the session is fresh
			if !sess.Fresh() {
				errChan <- errors.New("session should be fresh")
				return
			}

			// Save the session
			if saveErr := sess.Save(); saveErr != nil {
				errChan <- saveErr
				return
			}

			// release the session
			sess.Release()

			// Release the context
			app.ReleaseCtx(localCtx)

			// Acquire a new context
			localCtx = app.AcquireCtx(&fasthttp.RequestCtx{})
			defer app.ReleaseCtx(localCtx)

			// Set the session id in the header
			localCtx.Request().Header.SetCookie("session_id", id)

			// Get the session
			sess, err = store.Get(localCtx)
			if err != nil {
				errChan <- err
				return
			}
			defer sess.Release()

			// Get the value
			name := sess.Get("name")
			if name != "john" {
				errChan <- errors.New("name should be john")
				return
			}

			// Get ID from the session
			if sess.ID() != id {
				errChan <- errors.New("id should be the same")
				return
			}

			// Check if the session is fresh
			if sess.Fresh() {
				errChan <- errors.New("session should not be fresh")
				return
			}

			// Delete the key
			sess.Delete("name")

			// Get the value

Subdomains

Frequently Asked Questions

What does Test_Session_Concurrency() do?
Test_Session_Concurrency() is a function in the fiber codebase, defined in middleware/session/session_test.go.
Where is Test_Session_Concurrency() defined?
Test_Session_Concurrency() is defined in middleware/session/session_test.go at line 1425.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free