server

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: Apache-2.0 Imports: 12 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server is mock-1c: a small HTTP service that behaves like the HTTP service of a 1C installation for sales orders, for the test stand.

Input: POST /hs/orders (a new order) and GET /hs/orders?external_id= (a lookup). Output: JSON. It writes only to its own schema mock_onec in the stand's database, so that a benchmark can count effects with a query.

A request with an external_id that is already there changes nothing and answers 200 with the stored order (an idempotent receiver). A request without an external_id always makes a new order: this is how a client without keys, like the baseline configuration C0 of the benchmark, behaves.

Fault knobs (set from the environment by cmd, or by tests): the share of requests that commit the order and then answer 500; a fixed delay; a prefix of the business reference that gets a permanent refusal (422). POST /control sets the same three knobs for one tenant (package mocks/control), so that slots of the benchmark do not disturb each other.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(ctx context.Context, pool *pgxpool.Pool) error

Migrate creates the schema and the table of the mock if they are missing.

Types

type Config

type Config struct {
	FailAfterCommitRate float64       // MOCK_FAIL_AFTER_COMMIT_RATE: 0 to 1
	Latency             time.Duration // MOCK_LATENCY_MS
	RejectRefPrefix     string        // MOCK_REJECT_REF_PREFIX; "" rejects nothing
	FailCancel          bool          // MOCK_FAIL_CANCEL: every cancel answers 500 (the test of a failed compensation)
}

Config holds the fault knobs.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the HTTP handler of the mock.

func New

func New(pool *pgxpool.Pool, cfg Config) *Server

New builds the server on a pool whose database has the mock schema (see Migrate).

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the routes of the mock.

func (*Server) SetFailAfterCommitRate

func (s *Server) SetFailAfterCommitRate(rate float64)

SetFailAfterCommitRate changes the share of requests that commit and then fail.

func (*Server) SetFailCancel

func (s *Server) SetFailCancel(fail bool)

SetFailCancel makes every cancel answer 500 (or stops doing so).

func (*Server) SetRejectRefPrefix

func (s *Server) SetRejectRefPrefix(prefix string)

SetRejectRefPrefix changes the prefix of business references that get a 422.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL